【发布时间】:2016-05-20 21:59:17
【问题描述】:
我有一个访问 .NET WebAPI 服务器端的 AngularJS Web 应用程序。身份验证是通过 AngularJS-OAuth2 库实现的。我在两个不同的端口号下将应用程序和 WebAPI 托管在 localhost 中。我还在服务器端启用了 Microsoft.Owin.Cors 包来处理跨域请求。
在 Chrome 中,GET 和 POST 请求将数据返回到前端。通过检查通过 Fiddler 的流量,我可以看到发送了一对请求/响应(预检/OPTIONS + 实际)以及请求和响应中的相关 CORS 标头(包括 origin 和 Access-Control-* 标头)。一切如预期。
但是,在 Internet Explorer 中,我的 GET 请求通过 $http 服务返回数据,但 POST 不返回。我可以检查没有预检请求或 CORS 标头(我认为 IE 将不同的端口视为同一来源)。在通过 Fiddler 检查 IE 中的 POST 请求/响应时,我可以观察到它返回 HTTP 状态 200 但状态为 Aborted(设置了 X-ABORTED-WHEN: SendingResponse 标志)。我还可以使用返回的正确数据检查 JSON 响应。
我也尝试设置高超时无济于事。 $http 调用如下所示:
return $http.post(apiUrl + "/search", service.getParameters(), { timeout: 600000 })
.success(function (data) {...
Fiddler 为 IE POST 请求显示如下内容:
同样(仅)在 IE 中,与此 POST 操作相同的按钮单击也会触发无意的页面刷新。
当正确的数据也返回到客户端并且 Chrome 完全没有任何问题时,为什么 Internet Explorer 只中止 POST 请求?
其他信息
请求:
POST https://localhost:44321/api//search HTTP/1.1
Content-Type: application/json;charset=utf-8
Accept: application/json, text/plain, */*
Authorization: Bearer <token>
Referer: https://localhost:44322/search
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
Host: localhost:44321
Content-Length: 202
DNT: 1
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: .ASPXANONYMOUS=<cookie>
回复:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: <file>
X-Powered-By: ASP.NET
Date: Wed, 10 Feb 2016 13:43:45 GMT
Content-Length: 2284
Fiddler 会话属性:
SESSION STATE: Aborted.
Request Entity Size: 202 bytes.
Response Entity Size: 2284 bytes.
== FLAGS ==================
BitFlags: [IsHTTPS, ClientPipeReused, ServerPipeReused] 0x19
X-ABORTED-WHEN: SendingResponse
X-CLIENTIP: 127.0.0.1
X-CLIENTPORT: 41889
X-EGRESSPORT: 41890
X-HOSTIP: ::1
X-PROCESSINFO: avp:3584
X-RESPONSEBODYTRANSFERLENGTH: 2,284
X-SERVERSOCKET: REUSE ServerPipe#168
== TIMING INFO ============
ClientConnected: 19:13:42.408
ClientBeginRequest: 19:13:42.444
GotRequestHeaders: 19:13:42.444
ClientDoneRequest: 19:13:42.772
Determine Gateway: 0ms
DNS Lookup: 0ms
TCP/IP Connect: 0ms
HTTPS Handshake: 0ms
ServerConnected: 19:13:42.413
FiddlerBeginRequest: 19:13:42.772
ServerGotRequest: 19:13:42.772
ServerBeginResponse: 19:13:45.360
GotResponseHeaders: 19:13:45.360
ServerDoneResponse: 19:13:45.360
ClientBeginResponse: 19:13:45.360
ClientDoneResponse: 19:13:45.360
Overall Elapsed: 0:00:02.915
The response was buffered before delivery to the client.
== WININET CACHE INFO ============
This URL is not present in the WinINET cache. [Code: 2]
* Note: Data above shows WinINET's current cache state, not the state at the time of the request.
* Note: Data above shows WinINET's Medium Integrity (non-Protected Mode) cache only.
【问题讨论】:
标签: angularjs internet-explorer asp.net-web-api xmlhttprequest cors