use*_*904 5 cookies aurelia electron
我必须通过Aurelia客户端访问远程网站.当用Electron包裹时,解决方案也应该有效.请求通过http.fetch()完成.此请求必须使用客户端设置的不同cookie多次完成.
设置cookie的各种尝试都失败了.它必须由客户端内的某个安全层引起.使用相同的机制设置其他标头可以正常工作.
如果请求中未指定cookie头,则该服务将返回一个内部正确处理的Set-Cookie头.后续请求将按预期发送收到的cookie,直到重新启动Electron客户端.此行为适用于大多数客户端,但不是我需要的特定问题.
据我所知,至少在三种不同的环境中会出现同样的问题:
chromium --disable-web-security --user-data-dir)我通过Apache Web服务器直接将index.html作为"file://"以及"http://"运行.访问的服务URL始终指向Internet中的相同服务.
import {inject} from 'aurelia-framework';
import {HttpClient} from 'aurelia-fetch-client';
import 'fetch';
@inject(HttpClient)
export class Overview {
constructor(http) {
http.configure(config => {
config
.useStandardConfiguration()
.withBaseUrl(this.url)
.withDefaults({
credentials: 'include',
mode: 'cors',
// Default headers
headers: {
'X-fetch-default-header': 'fetch-default-header',
'Cookie': 'fetch-default-cookie=test'
}
});
});
this.http = http;
}
fetchRoot(nodeId){
var myHeaders = new Headers();
myHeaders.append('X-my-header', 'my-header');
myHeaders.append('Cookie', 'header-cookie=test');
// Individual Headers Variant 1
this.http.fetch('',
{credentials: 'include', headers: {
cookie: 'fetch-inline-cookie=test',
'X-fetch-inline-header':'fetch-inline-header'
}
}).then(...);
// Individual Headers Variant 2
this.http.fetch('',
{credentials: 'include', headers: myHeaders})
.then(...);
}
Run Code Online (Sandbox Code Playgroud)
或者,相同的代码已经过测试,并且; path=/直接在后面进行了测试key=value.
使用包电子cookie,可以访问和操作document.cookie属性.设置的值在客户端重新启动时甚至是持久的.问题:
的fetchRoot(nodeId){}延长通过下面的代码:
require('electron-cookies')
document.cookie = 'document-cookie=test';
Run Code Online (Sandbox Code Playgroud)
尝试使用其他软件包(例如,不同的电子cookie和简单的装饰器fetch-cookie)似乎也遇到了同样的安全问题.在某些时候,不会为cookie执行"set header".
| 归档时间: |
|
| 查看次数: |
1383 次 |
| 最近记录: |