Handling redirection
ASIHTTPRequest will automatically redirect to a new URL when it encounters one of the following HTTP status codes, assuming a Location header was sent:
- 301 Moved Permanently
- 302 Found
- 303 See Other
When redirection occurs, the value of the response data (responseHeaders / responseCookies / responseData / responseString etc) will reflect the content received from the final location.
Cookies set on any of the urls encountered during a redirection cycle will be stored in the global cookie store, and will be represented to the server on the redirected request when appropriate.
You can turn off automatic redirection by setting the request’s shouldRedirect property to NO.
By default, automatic redirects always redirect using a GET request (with no body). This behaviour matches the way most browsers work, not the HTTP spec, which specifies that 301 and 302 redirects should use the original method.
To preserve the original method (including the request body) for 301 and 302 redirects, setshouldUseRFC2616RedirectBehaviour to YES on the request before you start it.
这个属性的意思是,ASIHTTPRequest 默认会自动帮你 redirection,但是默认是用 "GET" 的方式,如果你的 request 是 Post,那么你要把 setshouldUseRFC2616RedirectBehaviour to YES
本文深入探讨ASIHTTPRequest在遇到特定HTTP状态码时的自动重定向机制,包括重定向过程中的数据处理、Cookie管理以及如何在保持原始请求方法的同时进行重定向。此外,介绍了如何通过设置shouldRedirect和shouldUseRFC2616RedirectBehaviour来控制自动重定向行为。
4488

被折叠的 条评论
为什么被折叠?



