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!