gpt4 book ai didi

cocoa - 为什么我收到 1 个 302 响应时会得到两个重定向响应?

转载 作者:行者123 更新时间:2023-12-03 16:34:19 24 4
gpt4 key购买 nike

我使用以下代码:

- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSHTTPURLResponse *)response {
NSLog(@"Received redirect Response: %@ %@", [response allHeaderFields], [NSHTTPURLResponse localizedStringForStatusCode:[response statusCode]]);
return request;
}

当我收到包含以下 header 数据的 302 时:

< HTTP/1.1 302 Found  
< Date: Wed, 03 Mar 2010 07:47:17 GMT
< Server: lighttpd/1.4.19
< Content-length: 0
< Content-type: text/html;charset=utf-8
< Location: `<new Location>`
< Vary: Accept-Encoding

这是 gdb 控制台中的输出:

2010-03-03 08:42:03.265 MyProg[68106:207] Received redirect Response: (null) server error 2010-03-03 08:42:14.414 MyProg[68106:207] Received redirect Response: {
Connection = "Keep-Alive";
"Content-Encoding" = gzip;
"Content-Length" = 20;
"Content-Type" = "text/html;charset=utf-8";
Date = "Wed, 03 Mar 2010 07:42:10 GMT";
"Keep-Alive" = "timeout=15, max=100";
Location = "<new Location>";
Server = "lighttpd/1.4.19";
Vary = "Accept-Encoding"; } found

当使用 Curl 时,我只得到一个响应,并且 Tracedump 也给出相同的信息,因此我确信服务器只发送一个重定向。
为什么这个选择器被调用两次?

最佳答案

connection:willSendRequest:redirectResponse: 在每个请求之前被调用,因此它在原始请求上调用一次,这不是重定向,因此响应为零;然后在加载重定向目标时调用它,其中响应是对初始请求的 302 响应。

关于cocoa - 为什么我收到 1 个 302 响应时会得到两个重定向响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2369608/

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