commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ravi Mutyala <ravi.muty...@gawab.com>
Subject [httpclient] problem in sending the correct http request
Date Tue, 01 Jun 2004 10:18:32 GMT
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


Mime
View raw message