gpt4 book ai didi

ios - 使用 NSURLConnection 获取 302 HTTP 重定向的响应主体

转载 作者:行者123 更新时间:2023-11-29 10:38:38 34 4
gpt4 key购买 nike

我将 HTTP GET 请求发送到一个 URL,使用 NSURLConnection 和委托(delegate)。使用 HTTP 302 重定向请求,执行新请求并检索数据。

问题是我不想要重定向的 HTTP 请求的主体,而是原始重定向响应的内容。

我已经实现了 - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response 是用 redirectRepsonse 调用的,但是 connection:didReceiveData 在新的重定向请求返回之前不会被调用。

到目前为止,除了使用基于 CFNetwork 的方法外,我还没有找到任何解决方案。

更新:我创建了一个带有问题的示例项目供您使用:https://github.com/snod/302RedirectTest

有什么想法吗?

最佳答案

来自docs-connection:willSendRequest:redirectResponse::

To receive the body of the redirect response itself, return nil to cancel the redirect. The connection continues to process, eventually sending your delegate a connectionDidFinishLoading or connection:didFailLoadingWithError: message, as appropriate.

关于ios - 使用 NSURLConnection 获取 302 HTTP 重定向的响应主体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25683318/

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