我有一个ASP.net web API 2项目。在我的本地计算机上,所有调用都没有任何问题,但在真实服务器上,对API的调用重定向到your-way.eu。有没有人知道这种行为可能来自哪里?
更新:
重定向仅发生在浏览器中,而不是fiddler。重定向的类型为301。
以下是我们执行的JavaScript调用:
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("GET", "http://testapi.myserver.de/api/Cart");
xhr.setRequestHeader("authorization", "Basic blabla");
xhr.setRequestHeader("cache-control", "no-cache");
xhr.send(data);
这就是回应:
HTTP/1.1 301 Moved Permanently
Date: Thu, 02 Jun 2016 09:44:11 GMT
Server: Apache/2.2.16 (Debian)
Location: http://50743.your-way.eu/webinar/56?pn/api/Cart
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 274
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
非常奇怪的是,我们使用的是IIS而不是Apache。
以下是请求标头:
使用XHR制作时,我只能在此处获得OPTIONS请求:
Host: testapi.mywebserver.de
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Access-Control-Request-Method: GET
Origin: http://localhost
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
Access-Control-Request-Headers: authorization, cache-control
Accept: */*
Referer: http://localhost/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Browserheaders:
Accept: text/html, application/xhtml+xml, image/jxr, */*
Accept-Language: de-DE,de;q=0.8,en-GB;q=0.5,en;q=0.3
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586
Accept-Encoding: gzip, deflate
Host: testapi.mywebserver.de
Connection: Keep-Alive