首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NWJS跨域回源安全

NWJS跨域回源安全
EN

Stack Overflow用户
提问于 2017-05-06 18:29:11
回答 1查看 1.8K关注 0票数 0

我正在尝试连接到我的ISP调制解调器来获取一些隐藏的数据,所以我创建了一个包含一些javascript的html页面。我使用xmlhttprequest登录到页面,它可以工作,但我无法获得cookie,这是进行请求和获取隐藏数据所必需的。我读到使用NWJS我可以绕过CORS limitations...but,我不知道我做错了什么。我实际使用的是最新的SDK NWJS 0.22.1

这是我的package.json:

代码语言:javascript
复制
{
 "main": "index.html",
 "name": "Liveboxinfos",
 "description": "test app",
 "version": "1.0.0",
 "nodejs": true,
 "node-remote": "http://192.168.1.1/*",
 "permissions": ["*://*/*"],
 "chromium-args": "--disable-web-security --user-data-dir",
 "window": {
 "title": "node-webkit demo",
 "icon": "link.png",
 "toolbar": true,
 "frame": true,
 "width": 1200,
 "height": 600,
 "position": "center",
 "min_width": 600,
 "min_height": 400,
 "max_width": 1200,
 "max_height": 600
 }
}

下面是我的index.html的javascript部分:

代码语言:javascript
复制
var ip = "192.168.1.1";
var password = "password";

var HTTP = new XMLHttpRequest();
var url = "http://" + ip;
var params = '{"service":"sah.Device.Information","method":"createContext","parameters":{"applicationName":"so_sdkut","username":"admin","password":"' + password + '"}}';

HTTP.open("POST", url, false);
HTTP.setRequestHeader("Content-Type", "application/x-sah-ws-4-call+json");
HTTP.setRequestHeader("Authorization", "X-Sah-Login");
HTTP.withCredentials = true;
HTTP.onreadystatechange = function() {//Call a function when the state changes.
    if(HTTP.readyState == 4 && HTTP.status == 200) {
        //alert(HTTP.responseText);
    }
}

HTTP.send(params);

const regex = /contextID":"(.*?)"/;
const Received = HTTP.responseText;
const cookie = HTTP.getResponseHeader("set-cookie");

这是我的测试应用程序,您可以看到cookie = null...

EN

回答 1

Stack Overflow用户

发布于 2017-05-06 19:18:04

不是CORS。基本上,您不能通过使用XHR从其他域获取cookie。

使用NWJS,您可以简单地使用http.request/http.get来获取cookie。

@查看https://nodejs.org/api/http.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43819338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档