gpt4 book ai didi

angularjs - 为什么 Internet Explorer 中收不到 POST 响应数据?

转载 作者:行者123 更新时间:2023-12-02 23:08:06 25 4
gpt4 key购买 nike

我有一个访问 .NET WebAPI 服务器端的 AngularJS Web 应用程序。身份验证是通过 AngularJS-OAuth2 库实现的。我将应用程序和 WebAPI 托管在 localhost 中的两个不同端口号下。我还在服务器端启用了 Microsoft.Owin.Cors 包来处理跨域请求。

在 Chrome 中,GET 和 POST 请求将数据返回到前端。通过 Fiddler 检查流量,我可以看到发送了一对请求/响应(预检/选项 + 实际),以及请求和响应中的相关 CORS header (包括 origin 和 Access-Control-* header )。一切都如预期。

但是,在 Internet Explorer 中,我的 GET 请求通过 $http 服务返回数据,但 POST 则不会。我可以检查是否存在预检请求或 CORS header (我认为 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 请求显示如下内容:

enter image description here

此外(仅)在 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 属性:

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.

最佳答案

我相信你会被 P3P policy requirement 咬伤IE在这里:

Internet Explorer supports a cookie-restricting privacy feature called P3P. Web developers often get tripped up by it because no other browser implements the P3P standard.

它看起来与那些 QA 类似:

Here's a blog post举例说明如何发送 P3P 信息。这是 document from Microsoft关于P3P配置

关于angularjs - 为什么 Internet Explorer 中收不到 POST 响应数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35317088/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com