Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Location header missing in HTTP redirect response

807580Aug 7 2009 — edited Aug 19 2009
Hello,

I have a scenario in which I am sending a POST request to a server. The server replies with a 302 (Moved temporarily) status and sets the "Location" header to a URL which contains, in the form of parameter-value pairs, the actual results of the initial request. I am therefore interested in this new URL, but I do not want to actually follow it; I just need to get it. So far, I have not managed to do this.

If I set redirection to false, i.e.
con.setInstanceFollowRedirects(false);
then, after I submit the POST, the "Location" header is empty. As a side-note, I know it is not supposed to be empty, as I have tested this is Firefox and the "Location" header was set correctly.

If I set redirection to true, i.e.
con.setInstanceFollowRedirects(true);
then I end up with a 405 (Method not allowed) status message.

How can I get this URL? Is it possible to somehow read the "Location" header without performing the actual redirect?

Thanks in advance,
Catalin
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 16 2009
Added on Aug 7 2009
7 comments
3,681 views