Android 重定向(返回代码 302)处理
我正在使用 HttpClient 对服务器 URL 执行 Post 请求。服务器 URL 正在重定向我,并且似乎我的 HttpClient 正在自动重定向。我想拦截重定向响应 302。我无法使用 setFollowRedirects(false)。我想知道是否有办法拦截 302 响应并停止自动重定向?我看到我们可以使用 HttpURL Connection 来实现这一点
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setFollowRedirects(false);
,但是我想使用 HttpClient 和 HttpPost 来避免当前实现中的巨大变化。有什么办法可以达到同样的目的吗?
I am using HttpClient to do Post request to a server URL. The server URL is redirecting me and seems like my HttpClient is getting redirected automatically. I wanted to intercept the redirect response 302. I am unable to use setFollowRedirects(false). I wanted to know if there is anyway to do intercept the 302 response and stop Auto redirection?? I saw that we can achieve this using HttpURL Connection
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setFollowRedirects(false);
However I want to use HttpClient and HttpPost to avoid huge changes in my current implementation. Is there any way to achieve the same?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ResponseHandler.handleResponse(HttpResponse response)
是HttpClient
类的一部分。此外,大多数
HttpClient.execute
方法都会返回HttpResponse
。使用 HttpResponse.getStatusLine().getStatusCode() 。另请参阅
org.apache.http.client.RedirectHandler
。ResponseHandler.handleResponse(HttpResponse response)
is part of theHttpClient
class.Also most of the
HttpClient.execute
methods return anHttpResponse
. UseHttpResponse.getStatusLine().getStatusCode()
.Also look at
org.apache.http.client.RedirectHandler
.