List Info

Thread: Using "removeRequestHeader" method.




Using "removeRequestHeader" method.
user name
2006-03-29 16:05:30
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:rsharmaairvana.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:TGerdesOldRepublicTitle.com]
Sent: Wednesday, March 29, 2006 9:53 AM
To: httpclient-devjakarta.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&q
uot;, 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 http
s://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 http
s://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-unsubscribejakarta.apache.org
For additional commands, e-mail: httpclient-dev-helpjakarta.apache.org


------------------------------------------------------------
---------
To unsubscribe, e-mail: httpclient-dev-unsubscribejakarta.apache.org
For additional commands, e-mail: httpclient-dev-helpjakarta.apache.org

Using "removeRequestHeader" method.
user name
2006-03-30 14:36:37
Hi Tom,

the mailing list archive is your friend:
http://mail-archives.apache.org/mod_mbox/jakarta
-httpclient-dev/
http://mail-archives.apache.org/mod_mbox/jakarta-http
client-dev/200603.mbox/%3c8A4F55A988C94B40B668BADA133C5CE40A
81C101mn-msp-exchange.OldRepublicTitle.com%3e

> 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.  

Or maybe you've overlooked a tiny little detail, such as
the HTTP version
that IE is using or whether the request is sent through a
proxy.

> 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?

If the server likes your requests, then you're doing things
right 
If you use our PostMethod, you always have a request entity.
Setting
name/value pairs directly at the method will implicitly
create one,
using url-encoded form parameters.

cheers,
  Roland

------------------------------------------------------------
---------
To unsubscribe, e-mail: httpclient-dev-unsubscribejakarta.apache.org
For additional commands, e-mail: httpclient-dev-helpjakarta.apache.org

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )