commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@bluewin.ch>
Subject Re: [httpclient] problem in sending the correct http request
Date Tue, 01 Jun 2004 11:20:41 GMT
Ravi,

If you are lucky setting content type to TEXT/PLAIN

httppost.setRequestHeader("Content-type", "TEXT/PLAIN");

instead of

httppost.setRequestHeader("Content-type", "text/xml;
charset=ISO-8859-1");

may do the trick. If you are unlucky, the one sure way to know would be
to get hold of the complete HTTP request sent by the browser. There are
several possibilities to do so: (1) use a proxy capable of HTTPS
proxying (not just tunneling) (2) use a browser plugin that can display
request/response headers for a particular HTTP session

In order to see what exactly HttpClient sends across the wire you way
want to activate the wire log

http://jakarta.apache.org/commons/httpclient/logging.html

Oleg

On Tue, 2004-06-01 at 12:18, Ravi Mutyala wrote:
> Hi,
> 
> I am trying to connect to HTTPS adaptor of an external system. I'm 
> getting the correct response from the adaptor when  I connect to the 
> system with the following html form submit.
> 
> <HTML>
> <HEAD> </HEAD>
>  <body onLoad = "javascript:document.forms[0].method = 
> 'POST';javascript:document.forms[0].submit()">
> <FORM name ="sampleform" method = "POST" ENCTYPE="TEXT/PLAIN" action = 
> https://url.com/progname">
> <input type ="hidden" name="XMLMSG"  value = "<A1>  <B1> abc </B1>
<B1> 
> bd</B1> <B2> 1 </B2> </A1> "/>
> </FORM>
> </body></HTML>
> 
> Now, I'm trying to send the same request using the postmethod of 
> httpclient. I wrote the following program. But now I'm able to connect 
> to the Adaptor but the adaptor is retuning an error saying that the 
> request is not proper. I know that the request is not properly formed. 
> But I'm not able to find out where the problem is in making the request.
> 
> I have checked the httpclient documentation and tried to add the xml 
> message in a number of ways but failed.
> 
> It would be of great help if someone can give me some clues on the 
> problem. I tried using addParameter() and setRequestBody() but both gave 
> me errors.
> I can't get the exact html request thatz going to the external system. 
> Is there any way I can find how the request object is formed.
> 
> Thanks in advance.
> 
> /
> Ravi.
> 
> java program using httpclient.
> 
> ...............................
> .......................................
> String connectString;
> connectString =  "https://url.com/progname";
> HttpClient httpclient = new HttpClient();
> 
> /* SSL code */
> Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
>  try {
>             KeyManagerFactory kmf = 
> KeyManagerFactory.getInstance("SunX509", "SunJSSE") ;
>         } catch (NoSuchAlgorithmException e1) {
>             // TODO Auto-generated catch block
>             e1.printStackTrace();
>         } catch (NoSuchProviderException e1) {
>             // TODO Auto-generated catch block
>             e1.printStackTrace();
>         }
>        
> httppost = new PostMethod(connectString);
> 
> NameValuePair nvp1 = new NameValuePair();
> nvp1.setName("XMLMSG");
> nvp1.setValue("<A1>  <B1> abc </B1> <B1> bd</B1> <B2>
1 </B2> </A1>");
>        
> httppost.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
> 
> httppost.addParameter(nvp1);
> 
> // httppost.setRequestBody(<input type="hidden" name="XMLMSG" 
> value="<A1>  <B1> abc </B1> <B1> bd</B1> <B2> 1 </B2>
</A1>"); 
> /* tried this way also but no result :( */
> 
>  try {
>             httpclient.executeMethod(httppost);
>           } catch (HttpException e) {
>                 e.printStackTrace();
>         } catch (IOException e) {
>               e.printStackTrace();
>         }
>        
>           System.out.println(httppost.getStatusLine().toString());
> ..................................
> ....................................
> .......................................
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 


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


Mime
View raw message