我想在第二角提出下面的邮政请求。
http://gearman.local.eviry.com/info具有如下的身体
{"gearman_servers" :[{
"name" : "server 1",
"addr" : "192.168.1.115"
},
{
"name" : "Server 2",
"addr" : "192.0.1.126"
}
]}我已经确保这在角2之外工作。(使用邮递员)我还确保启用了CORS。
以下是我的角码
var url = 'http://gearman.local.eviry.com' +
'/info';
var GEARMAN_DATA = {"gearman_servers" :[{
"name" : "server 1",
"addr" : "192.168.1.115"
},
{
"name" : "Server 2",
"addr" : "192.0.1.126"
}]};
let body = JSON.stringify(GEARMAN_DATA);
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
this.http.post(url, body, options)
.map(res => res.json())
.subscribe(
data => {console.log(data);},
err => this.logError(err),
() => console.log('Fetching complete for Server Metrics')
);
logError(err:Response){
console.log("some error");
console.log(err);
}然而,这样做会给我带来一个错误。
XMLHttpRequest cannot load http://gearman.local.eviry.com/info. Invalid HTTP status code 405此外,当我在logError函数中输出错误时,我会得到以下内容:
http://grab.by/O7s8
很难弄清这一要求有什么问题。
请求头如图所示
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Cache-Control:no-cache
Connection:keep-alive
Host:gearman.local.eviry.com
Origin:http://evil.com/
Pragma:no-cache
Referer:http://localhost:3000/gearman-ui/job-queue
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36
X-FirePHP:0.4.4
X-FirePHP-Version:0.4.4
X-Wf-Max-Combined-Size:262144响应标头如图所示
Allow:POST
Cache-Control:no-cache
Connection:Keep-Alive
Content-Length:4519
Content-Type:text/html; charset=UTF-8
Date:Mon, 15 Feb 2016 08:32:54 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.2.24 (Unix) mod_ssl/2.2.24 OpenSSL/1.0.1e-fips如果有人使用邮递员,我有下面的代码可以工作。我必须使用棱角实现相同的功能(请注意,您将无法访问http://gearman.local.eviry.com)。
发布于 2016-02-15 08:18:05
我尝试了一下您的请求(请参阅这个plunkr:http://plnkr.co/edit/6sbNYgIlCMNLkyyRerEk?p=preview),并且似乎您预先准备的请求的回复是不正确的:
XMLHttpRequest cannot load http://gearman.local.eviry.com/info. Response for preflight is invalid (redirect)在看了这一次的答复之后,我有以下几点:
这个请求的302状态代码是我认为的问题。而且我在它的回复中没有看到任何CORS头..。
https://stackoverflow.com/questions/35401520
复制相似问题