Skip to content Skip to sidebar Skip to footer

Httppost -> Redirect -> Location Or Body Of Response Needed

Here is Java code that POSTs data to a website and than gets redirected as a response (status 302). It works perfectly on my PC (Eclipse, Java, Ubuntu), it does exactly what I want

Solution 1:

I have found the problem!

httpclient.getParams().setParameter("http.protocol.version",
                HttpVersion.HTTP_1_0);

Just changing this one line - version 1_0 works and 1_1 does not. Don't ask me why :)

Thank you all!

Solution 2:

Please try the following code. The location in the header is missing, because the page has already redirected. So we can disable redirection to get the location tag.

httpclient.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, false);

Solution 3:

Try calling this after you create your http client so that it follows your redirect

httpclient.getParams().setParameter("http.protocol.allow-circular-redirects", true);

Post a Comment for "Httppost -> Redirect -> Location Or Body Of Response Needed"