Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
936 views
in Technique[技术] by (71.8m points)

http - How to process the redirect in post method using HttpClient?

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

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

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?

Anyone can help? THX.!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

From RFC 2616:

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.

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

You can disable automatic following of redirects in Apache HTTP client. For example:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...