hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gerdes, Tom" <TGer...@OldRepublicTitle.com>
Subject RE: Using "removeRequestHeader" method.
Date Wed, 29 Mar 2006 16:05:30 GMT
Thanks for the information.  The reason I was attempting to remove these
request headers was to imitate what the Internet Explorer was doing when
it does a post request to the same web page.  Maybe Internet Explorer is
not following the rules for HTTP protocol.  

I have only been using the request entity when doing a multi-part post
request.  When the post includes only text type parameters I do not
create the request entity.  Am I doing that right?

-----Original Message-----
From: Rajat Sharma [mailto:rsharma@airvana.com] 
Sent: Wednesday, March 29, 2006 8:53 AM
To: HttpClient Project
Subject: RE: Using "removeRequestHeader" method.

Hi Tom,

some request headers are handled automatically by HTTP client,
in order to ensure correct HTTP requests or to support features
that should not require application code. These headers will be
inserted at the time you execute the request. You can not remove
them using removeRequestHeader(). Examples are:

Host:
  is required for HTTP/1.1 - change to HTTP/1.0 to remove
User-Agent:
  taken from the parameters, try (un)setting it there
Content-Type:
  taken from the request entity
Content-Length:
  taken from the request entity if present

You should be aware that removing such headers will interfere
with the operation of the HTTP protocol. For example, you are
trying to enforce connection keep-alive. That requires either a
Content-Length header, or HTTP/1.1 with chunked encoding.
If you want to remove Host and Content-Length headers, you
can't have connection keep-alive. Play at your own risk ;-)

cheers,


-----Original Message-----
From: Gerdes, Tom [mailto:TGerdes@OldRepublicTitle.com]
Sent: Wednesday, March 29, 2006 9:53 AM
To: httpclient-dev@jakarta.apache.org
Subject: Using "removeRequestHeader" method.


I apologize for reposting this email...  I accidently deleted my email
response after returning to the office.   Did anyone have any ideas on
why this is not working?

 

I am trying to remove request headers from my "PostMethod" object before
sending a post operation to a server.   I use the "removeRequestHeader"
method as shown below.   Although, in my log it shows the request
headers as still being sent when I use the method "getRequestHeaders".
Am I using the "removeRequestHeader" correctly.  Are you the right group
to ask question of.  I am using commons Httpclient 3.0.

 

Java source code:

  System.out.println("This is the URI after get3: " + CurrentURI);

  System.out.println("The URI post3:
https://www.netteller.com/anchorlink/hbMain.cfm");

  PostMethod post3 = new
PostMethod("https://www.netteller.com/anchorlink/hbMain.cfm");

  post3.getParams().setParameter("http.socket.timeout", new
Integer(5000));

  post3.setRequestHeader("Accept", "image/gif, image/x-xbitmap,
image/jpeg, image/pjpeg, application/vnd.ms-excel,
application/vnd.ms-powerpoint, application/msword,
application/x-shockwave-flash, */*");

  post3.removeRequestHeader("User-Agent");

  post3.removeRequestHeader("Host");

  post3.removeRequestHeader("Content-Length");

  post3.removeRequestHeader("Content-Type");

  post3.setRequestHeader("Connection", "Keep-Alive");

  try { theclient.executeMethod(post3); }

  catch (HttpException he)

   { he.printStackTrace(System.out);

     System.out.println(he.getMessage().toString());

     ErrorMessageText = he.getMessage().toString();

     Email.send(EmailServer, ReplyToEmail, EmailForError, "", "",
"Anchor Bank - Positive Pay Error!", "Error Sending User Name and
Password to web site https://www.netteller.com/anchorlink/hbMain.cfm.
Method post3 in BANKARJ failed!  Here is the error Message: " +
ErrorMessageText, "", ntUserName, ntPassword, ReplyToEmail, "");

     BANKARJ.logoff(theclient, EmailServer, EmailForError, ntUserName,
ntPassword, ReplyToEmail);

   }

  catch (IOException ie)

   { ie.printStackTrace(System.out);

     System.out.println(ie.getMessage().toString());

     ErrorMessageText = ie.getMessage().toString();

     Email.send(EmailServer, ReplyToEmail, EmailForError, "", "",
"Anchor Bank - Positive Pay Error!", "Error Sending User Name and
Password to web site https://www.netteller.com/anchorlink/hbMain.cfm.
Method post3 in BANKARJ failed!  Here is the error Message: " +
ErrorMessageText, "", ntUserName, ntPassword, ReplyToEmail, "");

     BANKARJ.logoff(theclient, EmailServer, EmailForError, ntUserName,
ntPassword, ReplyToEmail);

   }

  System.err.println(post3.getStatusLine().toString());

  CurrentURI = post3.getURI().toString();

  System.out.println("Here are the post3 Request Headers:");

  Header[] ReqHeadersp3 = post3.getRequestHeaders();

  for (int i=0; i<ReqHeadersp3.length; i++){
System.out.println(ReqHeadersp3[i]); }

  System.out.println("Here are the post3 Response Headers:");

  Header[] RspHeadersp3 = post3.getResponseHeaders();

  for (int i=0; i<RspHeadersp3.length; i++){
System.out.println(RspHeadersp3[i]); }

  System.err.println("Here are the new cookies after post3:");

  Cookie[] p3aCookies = httpstate.getCookies();

  for (int i=0; i<p3aCookies.length; i++){ System.err.println(i + ". " +
p3aCookies[i]); }

  //System.out.println("Here is the post3 Response Body:");

  //System.out.println(post3.getResponseBodyAsString());

  post3.releaseConnection();

 

Here is a clip out of my log:

 

Here are the post3 Request Headers:   

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/vnd.ms-excel, application/vnd.ms-powerpoint, application

 /msword, application/x-shockwave-flash, */*


Connection: Keep-Alive


User-Agent: Jakarta Commons-HttpClient/3.0


Host: www.netteller.com


Cookie: $Version=0; ASP.NET_SessionId=mznsco45afcwmrby55bsif45; $Path=/


Cookie: $Version=0; JHA=060327205627717e524c1c7bae532d2b32323ab33f40;
$Path=/                                                    

Content-Length: 208


Content-Type: application/x-www-form-urlencoded 

 

Any help you can give would be greatly appreciated!


 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org


Mime
View raw message