How my HttpClient should react on server response 302 Object Moved ?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alleo_Sortes
Posted On:   Friday, December 20, 2002 07:29 PM

I'm using custom-made HttpClient which works like a Browser. The problem is that I can't go through request redirection like 301 or 302 . The situation is, HttpClient: gets respond HTTP/1.1 302 Object Moved ; reads header field Location ; assembles new request using the protocol ( http:// ) + Host header field + value of Location field; reads HttpUrlConnection input stream (context data); sends request to the new URL using method of previous call. Questions: Why do I get response to the redirect call different from a Browser? Browser    More>>

I'm using custom-made HttpClient which works like a Browser. The problem is that I can't go through request redirection like 301 or 302 .


The situation is, HttpClient:


  • gets respond HTTP/1.1 302 Object Moved ;
  • reads header field Location ;
  • assembles new request using the protocol ( http:// ) + Host header field + value of Location field;
  • reads HttpUrlConnection input stream (context data);
  • sends request to the new URL using method of previous call.


Questions:

  1. Why do I get response to the redirect call different from a Browser? Browser gets a rigth response (of course). My application gets another redirect response and finally 200 OK response but along with empty context.
  2. Server responds to my POST request with redirection code 302 and Location header field equals to something like /folder1/folder2/servlet?x=y . Will it be correct to make POST request to URL loking like http://www.website.com/folder1/folder2/servlet?x=y ?
  3. Using a proxy log I see what HTTP headers are going back and force. My headers are the same. But, server reacts to my response differently. Is it possible to be a HttpUrlConnection bug?


Thank you evryone for any hint.

   <<Less

Re: How my HttpClient should react on server response 302 Object Moved ?

Posted By:   Myongki_Kim  
Posted On:   Wednesday, January 15, 2003 09:41 PM


Q1

use setInstanceFollowRedirects(false) methods. Default HttpUrlConnection's setting is true, which connection redirects(response 30x) is automatic.



Q2

URL class has URL(URL context, String spec) constructor.
Context is current url and spec is Location Header's value.
Therefore, next url is
new URL(prevURL, location_header_value).toString()



Q3

same as Q1




Sorry for my poor english

About | Sitemap | Contact