如何使用HttpClient处理post方法中的重定向? [英] How to process the redirect in post method using HttpClient?

查看:153
本文介绍了如何使用HttpClient处理post方法中的重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我将xml文件发布到服务器,但有时服务器将发回302然后重定向。

In My App , I POST a xml file to the server , but sometimes the server will send back 302 and then redirect .

但是,重定向后,方法变为GET,而不是POST,并且我在xml文件中的数据无法传送到服务器。

However , after the redirecting the method become GET , not POST, and my data in xml file can't deliver to server.

最后我得到的状态代码是404。

And finally the status code I got is 404.

有没有办法自行处理重定向?重定向发生时我可以做些什么吗?

Is there some way to process the redirect by myself ? Can I do something when the redirecting is happening?

任何人都可以提供帮助吗? THX。!

Anyone can help? THX.!

推荐答案

来自 RFC 2616


如果收到302状态代码为了响应
GET或HEAD以外的请求,除非用户可以确认,否则用户代理不得自动重定向
请求,因为这可能会改变b b b的条件。请求已经发出。

If the 302 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.

您确定您的服务器没有使用' POST,redirect,GET '成语?

Are you sure your server isn't using the 'POST, redirect, GET' idiom?

你可以禁用Apache HTTP客户端中的重定向自动跟踪。例如:

_httpClient = new DefaultHttpClient();
_httpClient.getParams().setParameter(
    ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE);

这篇关于如何使用HttpClient处理post方法中的重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆