You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Iker Bilbao <ib...@tid.es> on 2003/04/21 16:31:17 UTC

Post and https

Hello,

  I am trying to make a post to an https server and I can not make it
  work. I have what is was in the tutorial for posting but I get the
  following error:
            A recoverable exception occurred, retrying.  java.net.SocketException: Software caused connection
abort: JVM_recv in socket input stream read
  I have retried the operation but it does not work.

  The GetMehtod works well but not post.

  Here is my code:
  -------------------
  Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
  System.getProperties().put("java.protocol.handler.pkgs", "org.apache.commons.httpclient.HttpClient");
  System.setProperty("javax.net.ssl.trustStore","C:\\.keystore");
  System.setProperty("javax.net.ssl.keyStore","C:\\.keystore");
  System.setProperty("javax.net.ssl.keyStorePassword","password");

  HttpClient client = new HttpClient();
  client.getState().setCredentials("Realm",new
UsernamePasswordCredentials("user","password"));

  PostMethod post = new PostMethod("https://server:1234" +"/gestorpiloto");
  NameValuePair[] data = {
    new NameValuePair("tipoOperacion","alta")
  };

  post.setRequestBody(data);
  post.setDoAuthentication( true );

  try
  {
     int status = client.executeMethod( post );
     System.out.println(status + "\n" + post.getResponseBodyAsString());
  }
  catch (HttpRecoverableException e)
  {
     System.err.println("A recoverable exception occurred, retrying.  " + e.getMessage());
  }
  catch (IOException e)
  {
     System.err.println("Failed to download file.");
     e.printStackTrace();
     System.exit(-1);
  }
  catch (Exception e)
  {
     e.printStackTrace();
  }
  
  -------------------

  Has anyone any idea o what I am doing wrong?

Thanks in advance por your help.
Iker


Re: Post and https

Posted by Vamsi Atluri <vk...@yahoo.com>.
Hi Oleg,

Getting the latest nightly build worked! Thank you all very much for the
help.

Regards,
-Vamsi

--- Oleg Kalnichevski <o....@dplanet.ch> wrote:
> Upgrade to the most recent nightly build. HTTP POST as implemented in
> 2.0a3 is well known to not work when used over HTTPS
> 
> Oleg
> 
> On Mon, 2003-04-21 at 21:13, Vamsi Atluri wrote:
> > I am using httpclient 2.0 alpha 3, with JDK 1.4.1, but I am using JSSE
> for
> > SSL.
> > 
> > -Vamsi
> > --- Oleg Kalnichevski <o....@dplanet.ch> wrote:
> > > What version of HttpClient are you using? If it is anything other
> than
> > > the most recent CVS snapshot, upgrade
> > > 
> > > Oleg
> > > 
> > > On Mon, 2003-04-21 at 20:48, Vamsi Atluri wrote:
> > > > Hi Iker,
> > > > 
> > > > Actually I have a problem (not so similar) with POST and HTTPS
> too. I
> > > am
> > > > trying to establish a connection to a https site and POST some
> data to
> > > it,
> > > > but the response is always a null. I am first doing a GET, which
> works
> > > > fine. But then the POST fails. The code I am using is:
> > > > 
> > > > import org.apache.commons.httpclient.*;
> > > > import org.apache.commons.httpclient.methods.*;
> > > > import java.io.*;
> > > > import java.security.*;
> > > > import java.util.*;
> > > > 
> > > > class TestSSLHttpClient
> > > > {
> > > > 	public static void main(String[] args)
> > > > 	{
> > > > 		try
> > > > 		{
> > > > 			String url = "https://test.abc.com/xyz";
> > > > 		
> > > > 			Security.addProvider(new
> com.sun.net.ssl.internal.ssl.Provider());
> > > > 	  		System.setProperty("java.protocol.handler.pkgs",
> > > > "com.sun.net.ssl.internal.www.protocol");		
> > > > 			System.out.println("Done setting SSL properties");
> > > > 			
> > > > 			HttpClient httpClient = new HttpClient();		
> > > > 			System.out.println("Got HttpClient: " + httpClient);
> > > > 		
> > > > 			GetMethod getMethod = new GetMethod(url);
> > > > 			System.out.println("Got HttpMethod: " + getMethod);
> > > > 		
> > > > 			int statusCode = -1;
> > > > 		
> > > > 			statusCode = httpClient.executeMethod(getMethod);
> > > > 		
> > > > 			System.out.println("statusCode: " + statusCode);
> > > > 		
> > > > 			byte[] responseBody = getMethod.getResponseBody();
> > > > 			
> > > > 			String resp = new String(responseBody);
> > > > 		
> > > > 			System.out.println("Response: " + resp);
> > > > 			
> > > > 			String xmlRequest = "<SomeXML>SomeXML</SomeXML>";
> > > > 			
> > > > 			PostMethod postMethod = new PostMethod(url);
> > > > 			
> > > > 			postMethod.setRequestBody(xmlRequest);
> > > > 			
> > > > 			System.out.println("Built PostMethod: " + postMethod);
> > > > 			
> > > > 			statusCode = -1;
> > > > 			
> > > > 			statusCode = httpClient.executeMethod(postMethod);
> > > > 			
> > > > 			System.out.println("statusCode: " + statusCode);
> > > > 			
> > > > 			resp = postMethod.getResponseBodyAsString();
> > > > 			
> > > > 			System.out.println("Response: " + resp);
> > > > 			
> > > > 			postMethod.releaseConnection();				
> > > > 		}
> > > > 		catch(Exception e)
> > > > 		{
> > > > 			System.out.println("#######################");
> > > > 			System.out.println("Error occurred:");
> > > > 			e.printStackTrace();
> > > > 			System.out.println("#######################");
> > > > 		}
> > > > 	}
> > > > }
> > > > 
> > > > The error I get is that postMethod.getResponseBodyAsString() is
> > > returning
> > > > a null. However, if I try to trap the outpup of
> > > > postMethod.getResponseBody() into a byte[], I get the following
> > > exception:
> > > > 
> > > > Error occurred:
> > > > java.lang.NullPointerException
> > > >         at
> > > >
> org.apache.commons.httpclient.HttpMethodBase.getResponseBody(HttpMeth
> > > > odBase.java:670)
> > > >         at
> > > >
> org.apache.commons.httpclient.methods.GetMethod.getResponseBody(GetMe
> > > > thod.java:293)
> > > >         at TestSSLHttpClient.main(TestSSLHttpClient.java:54)
> > > > 
> > > > Any help in resolving this would be grately appreciated.
> > > > 
> > > > -Vamsi
> > > > 
> > > > 
> > > > --- Iker Bilbao <ib...@tid.es> wrote:
> > > > > Hello,
> > > > > 
> > > > >   I am trying to make a post to an https server and I can not
> make
> > > it
> > > > >   work. I have what is was in the tutorial for posting but I get
> the
> > > > >   following error:
> > > > >             A recoverable exception occurred, retrying. 
> > > > > java.net.SocketException: Software caused connection
> > > > > abort: JVM_recv in socket input stream read
> > > > >   I have retried the operation but it does not work.
> > > > > 
> > > > >   The GetMehtod works well but not post.
> > > > > 
> > > > >   Here is my code:
> > > > >   -------------------
> > > > >   Security.addProvider(new
> com.sun.net.ssl.internal.ssl.Provider());
> > > > >   System.getProperties().put("java.protocol.handler.pkgs",
> > > > > "org.apache.commons.httpclient.HttpClient");
> > > > >  
> System.setProperty("javax.net.ssl.trustStore","C:\\.keystore");
> > > > >   System.setProperty("javax.net.ssl.keyStore","C:\\.keystore");
> > > > >  
> System.setProperty("javax.net.ssl.keyStorePassword","password");
> > > > > 
> > > > >   HttpClient client = new HttpClient();
> > > > >   client.getState().setCredentials("Realm",new
> > > > > UsernamePasswordCredentials("user","password"));
> > > > > 
> > > > >   PostMethod post = new PostMethod("https://server:1234"
> > > > > +"/gestorpiloto");
> > > > >   NameValuePair[] data = {
> > > > >     new NameValuePair("tipoOperacion","alta")
> > > > >   };
> > > > > 
> > > > >   post.setRequestBody(data);
> > > > >   post.setDoAuthentication( true );
> > > > > 
> > > > >   try
> > > > >   {
> > > > >      int status = client.executeMethod( post );
> > > > >      System.out.println(status + "\n" +
> > > post.getResponseBodyAsString());
> > > > >   }
> > > > >   catch (HttpRecoverableException e)
> > > > >   {
> > > > >      System.err.println("A recoverable exception occurred,
> retrying.
> > >  "
> > > > > + e.getMessage());
> > > > >   }
> > > > >   catch (IOException e)
> > > > >   {
> > > > >      System.err.println("Failed to download file.");
> > > > >      e.printStackTrace();
> > > > >      System.exit(-1);
> > > > >   }
> > > > >   catch (Exception e)
> > > > >   {
> > > > >      e.printStackTrace();
> > > > >   }
> > > > >   
> > > > >   -------------------
> > > > > 
> > > > >   Has anyone any idea o what I am doing wrong?
> > > > > 
> > > > > Thanks in advance por your help.
> > > > > Iker
> > > > > 
> > > > > 
> > > > >
> > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail:
> > > > > commons-httpclient-dev-unsubscribe@jakarta.apache.org
> > > > > For additional commands, e-mail:
> 
=== message truncated ===


__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com

Re: Post and https

Posted by Oleg Kalnichevski <o....@dplanet.ch>.
Upgrade to the most recent nightly build. HTTP POST as implemented in
2.0a3 is well known to not work when used over HTTPS

Oleg

On Mon, 2003-04-21 at 21:13, Vamsi Atluri wrote:
> I am using httpclient 2.0 alpha 3, with JDK 1.4.1, but I am using JSSE for
> SSL.
> 
> -Vamsi
> --- Oleg Kalnichevski <o....@dplanet.ch> wrote:
> > What version of HttpClient are you using? If it is anything other than
> > the most recent CVS snapshot, upgrade
> > 
> > Oleg
> > 
> > On Mon, 2003-04-21 at 20:48, Vamsi Atluri wrote:
> > > Hi Iker,
> > > 
> > > Actually I have a problem (not so similar) with POST and HTTPS too. I
> > am
> > > trying to establish a connection to a https site and POST some data to
> > it,
> > > but the response is always a null. I am first doing a GET, which works
> > > fine. But then the POST fails. The code I am using is:
> > > 
> > > import org.apache.commons.httpclient.*;
> > > import org.apache.commons.httpclient.methods.*;
> > > import java.io.*;
> > > import java.security.*;
> > > import java.util.*;
> > > 
> > > class TestSSLHttpClient
> > > {
> > > 	public static void main(String[] args)
> > > 	{
> > > 		try
> > > 		{
> > > 			String url = "https://test.abc.com/xyz";
> > > 		
> > > 			Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
> > > 	  		System.setProperty("java.protocol.handler.pkgs",
> > > "com.sun.net.ssl.internal.www.protocol");		
> > > 			System.out.println("Done setting SSL properties");
> > > 			
> > > 			HttpClient httpClient = new HttpClient();		
> > > 			System.out.println("Got HttpClient: " + httpClient);
> > > 		
> > > 			GetMethod getMethod = new GetMethod(url);
> > > 			System.out.println("Got HttpMethod: " + getMethod);
> > > 		
> > > 			int statusCode = -1;
> > > 		
> > > 			statusCode = httpClient.executeMethod(getMethod);
> > > 		
> > > 			System.out.println("statusCode: " + statusCode);
> > > 		
> > > 			byte[] responseBody = getMethod.getResponseBody();
> > > 			
> > > 			String resp = new String(responseBody);
> > > 		
> > > 			System.out.println("Response: " + resp);
> > > 			
> > > 			String xmlRequest = "<SomeXML>SomeXML</SomeXML>";
> > > 			
> > > 			PostMethod postMethod = new PostMethod(url);
> > > 			
> > > 			postMethod.setRequestBody(xmlRequest);
> > > 			
> > > 			System.out.println("Built PostMethod: " + postMethod);
> > > 			
> > > 			statusCode = -1;
> > > 			
> > > 			statusCode = httpClient.executeMethod(postMethod);
> > > 			
> > > 			System.out.println("statusCode: " + statusCode);
> > > 			
> > > 			resp = postMethod.getResponseBodyAsString();
> > > 			
> > > 			System.out.println("Response: " + resp);
> > > 			
> > > 			postMethod.releaseConnection();				
> > > 		}
> > > 		catch(Exception e)
> > > 		{
> > > 			System.out.println("#######################");
> > > 			System.out.println("Error occurred:");
> > > 			e.printStackTrace();
> > > 			System.out.println("#######################");
> > > 		}
> > > 	}
> > > }
> > > 
> > > The error I get is that postMethod.getResponseBodyAsString() is
> > returning
> > > a null. However, if I try to trap the outpup of
> > > postMethod.getResponseBody() into a byte[], I get the following
> > exception:
> > > 
> > > Error occurred:
> > > java.lang.NullPointerException
> > >         at
> > > org.apache.commons.httpclient.HttpMethodBase.getResponseBody(HttpMeth
> > > odBase.java:670)
> > >         at
> > > org.apache.commons.httpclient.methods.GetMethod.getResponseBody(GetMe
> > > thod.java:293)
> > >         at TestSSLHttpClient.main(TestSSLHttpClient.java:54)
> > > 
> > > Any help in resolving this would be grately appreciated.
> > > 
> > > -Vamsi
> > > 
> > > 
> > > --- Iker Bilbao <ib...@tid.es> wrote:
> > > > Hello,
> > > > 
> > > >   I am trying to make a post to an https server and I can not make
> > it
> > > >   work. I have what is was in the tutorial for posting but I get the
> > > >   following error:
> > > >             A recoverable exception occurred, retrying. 
> > > > java.net.SocketException: Software caused connection
> > > > abort: JVM_recv in socket input stream read
> > > >   I have retried the operation but it does not work.
> > > > 
> > > >   The GetMehtod works well but not post.
> > > > 
> > > >   Here is my code:
> > > >   -------------------
> > > >   Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
> > > >   System.getProperties().put("java.protocol.handler.pkgs",
> > > > "org.apache.commons.httpclient.HttpClient");
> > > >   System.setProperty("javax.net.ssl.trustStore","C:\\.keystore");
> > > >   System.setProperty("javax.net.ssl.keyStore","C:\\.keystore");
> > > >   System.setProperty("javax.net.ssl.keyStorePassword","password");
> > > > 
> > > >   HttpClient client = new HttpClient();
> > > >   client.getState().setCredentials("Realm",new
> > > > UsernamePasswordCredentials("user","password"));
> > > > 
> > > >   PostMethod post = new PostMethod("https://server:1234"
> > > > +"/gestorpiloto");
> > > >   NameValuePair[] data = {
> > > >     new NameValuePair("tipoOperacion","alta")
> > > >   };
> > > > 
> > > >   post.setRequestBody(data);
> > > >   post.setDoAuthentication( true );
> > > > 
> > > >   try
> > > >   {
> > > >      int status = client.executeMethod( post );
> > > >      System.out.println(status + "\n" +
> > post.getResponseBodyAsString());
> > > >   }
> > > >   catch (HttpRecoverableException e)
> > > >   {
> > > >      System.err.println("A recoverable exception occurred, retrying.
> >  "
> > > > + e.getMessage());
> > > >   }
> > > >   catch (IOException e)
> > > >   {
> > > >      System.err.println("Failed to download file.");
> > > >      e.printStackTrace();
> > > >      System.exit(-1);
> > > >   }
> > > >   catch (Exception e)
> > > >   {
> > > >      e.printStackTrace();
> > > >   }
> > > >   
> > > >   -------------------
> > > > 
> > > >   Has anyone any idea o what I am doing wrong?
> > > > 
> > > > Thanks in advance por your help.
> > > > Iker
> > > > 
> > > > 
> > > >
> > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> > > > commons-httpclient-dev-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
> > > > commons-httpclient-dev-help@jakarta.apache.org
> > > > 
> > > 
> > > 
> > > __________________________________________________
> > > Do you Yahoo!?
> > > The New Yahoo! Search - Faster. Easier. Bingo
> > > http://search.yahoo.com
> > > 
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > commons-httpclient-dev-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> > commons-httpclient-dev-help@jakarta.apache.org
> > > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > commons-httpclient-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > commons-httpclient-dev-help@jakarta.apache.org
> > 
> 
> 
> __________________________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo
> http://search.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
> 


Re: Post and https

Posted by Vamsi Atluri <vk...@yahoo.com>.
I am using httpclient 2.0 alpha 3, with JDK 1.4.1, but I am using JSSE for
SSL.

-Vamsi
--- Oleg Kalnichevski <o....@dplanet.ch> wrote:
> What version of HttpClient are you using? If it is anything other than
> the most recent CVS snapshot, upgrade
> 
> Oleg
> 
> On Mon, 2003-04-21 at 20:48, Vamsi Atluri wrote:
> > Hi Iker,
> > 
> > Actually I have a problem (not so similar) with POST and HTTPS too. I
> am
> > trying to establish a connection to a https site and POST some data to
> it,
> > but the response is always a null. I am first doing a GET, which works
> > fine. But then the POST fails. The code I am using is:
> > 
> > import org.apache.commons.httpclient.*;
> > import org.apache.commons.httpclient.methods.*;
> > import java.io.*;
> > import java.security.*;
> > import java.util.*;
> > 
> > class TestSSLHttpClient
> > {
> > 	public static void main(String[] args)
> > 	{
> > 		try
> > 		{
> > 			String url = "https://test.abc.com/xyz";
> > 		
> > 			Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
> > 	  		System.setProperty("java.protocol.handler.pkgs",
> > "com.sun.net.ssl.internal.www.protocol");		
> > 			System.out.println("Done setting SSL properties");
> > 			
> > 			HttpClient httpClient = new HttpClient();		
> > 			System.out.println("Got HttpClient: " + httpClient);
> > 		
> > 			GetMethod getMethod = new GetMethod(url);
> > 			System.out.println("Got HttpMethod: " + getMethod);
> > 		
> > 			int statusCode = -1;
> > 		
> > 			statusCode = httpClient.executeMethod(getMethod);
> > 		
> > 			System.out.println("statusCode: " + statusCode);
> > 		
> > 			byte[] responseBody = getMethod.getResponseBody();
> > 			
> > 			String resp = new String(responseBody);
> > 		
> > 			System.out.println("Response: " + resp);
> > 			
> > 			String xmlRequest = "<SomeXML>SomeXML</SomeXML>";
> > 			
> > 			PostMethod postMethod = new PostMethod(url);
> > 			
> > 			postMethod.setRequestBody(xmlRequest);
> > 			
> > 			System.out.println("Built PostMethod: " + postMethod);
> > 			
> > 			statusCode = -1;
> > 			
> > 			statusCode = httpClient.executeMethod(postMethod);
> > 			
> > 			System.out.println("statusCode: " + statusCode);
> > 			
> > 			resp = postMethod.getResponseBodyAsString();
> > 			
> > 			System.out.println("Response: " + resp);
> > 			
> > 			postMethod.releaseConnection();				
> > 		}
> > 		catch(Exception e)
> > 		{
> > 			System.out.println("#######################");
> > 			System.out.println("Error occurred:");
> > 			e.printStackTrace();
> > 			System.out.println("#######################");
> > 		}
> > 	}
> > }
> > 
> > The error I get is that postMethod.getResponseBodyAsString() is
> returning
> > a null. However, if I try to trap the outpup of
> > postMethod.getResponseBody() into a byte[], I get the following
> exception:
> > 
> > Error occurred:
> > java.lang.NullPointerException
> >         at
> > org.apache.commons.httpclient.HttpMethodBase.getResponseBody(HttpMeth
> > odBase.java:670)
> >         at
> > org.apache.commons.httpclient.methods.GetMethod.getResponseBody(GetMe
> > thod.java:293)
> >         at TestSSLHttpClient.main(TestSSLHttpClient.java:54)
> > 
> > Any help in resolving this would be grately appreciated.
> > 
> > -Vamsi
> > 
> > 
> > --- Iker Bilbao <ib...@tid.es> wrote:
> > > Hello,
> > > 
> > >   I am trying to make a post to an https server and I can not make
> it
> > >   work. I have what is was in the tutorial for posting but I get the
> > >   following error:
> > >             A recoverable exception occurred, retrying. 
> > > java.net.SocketException: Software caused connection
> > > abort: JVM_recv in socket input stream read
> > >   I have retried the operation but it does not work.
> > > 
> > >   The GetMehtod works well but not post.
> > > 
> > >   Here is my code:
> > >   -------------------
> > >   Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
> > >   System.getProperties().put("java.protocol.handler.pkgs",
> > > "org.apache.commons.httpclient.HttpClient");
> > >   System.setProperty("javax.net.ssl.trustStore","C:\\.keystore");
> > >   System.setProperty("javax.net.ssl.keyStore","C:\\.keystore");
> > >   System.setProperty("javax.net.ssl.keyStorePassword","password");
> > > 
> > >   HttpClient client = new HttpClient();
> > >   client.getState().setCredentials("Realm",new
> > > UsernamePasswordCredentials("user","password"));
> > > 
> > >   PostMethod post = new PostMethod("https://server:1234"
> > > +"/gestorpiloto");
> > >   NameValuePair[] data = {
> > >     new NameValuePair("tipoOperacion","alta")
> > >   };
> > > 
> > >   post.setRequestBody(data);
> > >   post.setDoAuthentication( true );
> > > 
> > >   try
> > >   {
> > >      int status = client.executeMethod( post );
> > >      System.out.println(status + "\n" +
> post.getResponseBodyAsString());
> > >   }
> > >   catch (HttpRecoverableException e)
> > >   {
> > >      System.err.println("A recoverable exception occurred, retrying.
>  "
> > > + e.getMessage());
> > >   }
> > >   catch (IOException e)
> > >   {
> > >      System.err.println("Failed to download file.");
> > >      e.printStackTrace();
> > >      System.exit(-1);
> > >   }
> > >   catch (Exception e)
> > >   {
> > >      e.printStackTrace();
> > >   }
> > >   
> > >   -------------------
> > > 
> > >   Has anyone any idea o what I am doing wrong?
> > > 
> > > Thanks in advance por your help.
> > > Iker
> > > 
> > > 
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > > commons-httpclient-dev-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail:
> > > commons-httpclient-dev-help@jakarta.apache.org
> > > 
> > 
> > 
> > __________________________________________________
> > Do you Yahoo!?
> > The New Yahoo! Search - Faster. Easier. Bingo
> > http://search.yahoo.com
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> commons-httpclient-dev-help@jakarta.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-httpclient-dev-help@jakarta.apache.org
> 


__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com

Re: Post and https

Posted by Oleg Kalnichevski <o....@dplanet.ch>.
What version of HttpClient are you using? If it is anything other than
the most recent CVS snapshot, upgrade

Oleg

On Mon, 2003-04-21 at 20:48, Vamsi Atluri wrote:
> Hi Iker,
> 
> Actually I have a problem (not so similar) with POST and HTTPS too. I am
> trying to establish a connection to a https site and POST some data to it,
> but the response is always a null. I am first doing a GET, which works
> fine. But then the POST fails. The code I am using is:
> 
> import org.apache.commons.httpclient.*;
> import org.apache.commons.httpclient.methods.*;
> import java.io.*;
> import java.security.*;
> import java.util.*;
> 
> class TestSSLHttpClient
> {
> 	public static void main(String[] args)
> 	{
> 		try
> 		{
> 			String url = "https://test.abc.com/xyz";
> 		
> 			Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
> 	  		System.setProperty("java.protocol.handler.pkgs",
> "com.sun.net.ssl.internal.www.protocol");		
> 			System.out.println("Done setting SSL properties");
> 			
> 			HttpClient httpClient = new HttpClient();		
> 			System.out.println("Got HttpClient: " + httpClient);
> 		
> 			GetMethod getMethod = new GetMethod(url);
> 			System.out.println("Got HttpMethod: " + getMethod);
> 		
> 			int statusCode = -1;
> 		
> 			statusCode = httpClient.executeMethod(getMethod);
> 		
> 			System.out.println("statusCode: " + statusCode);
> 		
> 			byte[] responseBody = getMethod.getResponseBody();
> 			
> 			String resp = new String(responseBody);
> 		
> 			System.out.println("Response: " + resp);
> 			
> 			String xmlRequest = "<SomeXML>SomeXML</SomeXML>";
> 			
> 			PostMethod postMethod = new PostMethod(url);
> 			
> 			postMethod.setRequestBody(xmlRequest);
> 			
> 			System.out.println("Built PostMethod: " + postMethod);
> 			
> 			statusCode = -1;
> 			
> 			statusCode = httpClient.executeMethod(postMethod);
> 			
> 			System.out.println("statusCode: " + statusCode);
> 			
> 			resp = postMethod.getResponseBodyAsString();
> 			
> 			System.out.println("Response: " + resp);
> 			
> 			postMethod.releaseConnection();				
> 		}
> 		catch(Exception e)
> 		{
> 			System.out.println("#######################");
> 			System.out.println("Error occurred:");
> 			e.printStackTrace();
> 			System.out.println("#######################");
> 		}
> 	}
> }
> 
> The error I get is that postMethod.getResponseBodyAsString() is returning
> a null. However, if I try to trap the outpup of
> postMethod.getResponseBody() into a byte[], I get the following exception:
> 
> Error occurred:
> java.lang.NullPointerException
>         at
> org.apache.commons.httpclient.HttpMethodBase.getResponseBody(HttpMeth
> odBase.java:670)
>         at
> org.apache.commons.httpclient.methods.GetMethod.getResponseBody(GetMe
> thod.java:293)
>         at TestSSLHttpClient.main(TestSSLHttpClient.java:54)
> 
> Any help in resolving this would be grately appreciated.
> 
> -Vamsi
> 
> 
> --- Iker Bilbao <ib...@tid.es> wrote:
> > Hello,
> > 
> >   I am trying to make a post to an https server and I can not make it
> >   work. I have what is was in the tutorial for posting but I get the
> >   following error:
> >             A recoverable exception occurred, retrying. 
> > java.net.SocketException: Software caused connection
> > abort: JVM_recv in socket input stream read
> >   I have retried the operation but it does not work.
> > 
> >   The GetMehtod works well but not post.
> > 
> >   Here is my code:
> >   -------------------
> >   Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
> >   System.getProperties().put("java.protocol.handler.pkgs",
> > "org.apache.commons.httpclient.HttpClient");
> >   System.setProperty("javax.net.ssl.trustStore","C:\\.keystore");
> >   System.setProperty("javax.net.ssl.keyStore","C:\\.keystore");
> >   System.setProperty("javax.net.ssl.keyStorePassword","password");
> > 
> >   HttpClient client = new HttpClient();
> >   client.getState().setCredentials("Realm",new
> > UsernamePasswordCredentials("user","password"));
> > 
> >   PostMethod post = new PostMethod("https://server:1234"
> > +"/gestorpiloto");
> >   NameValuePair[] data = {
> >     new NameValuePair("tipoOperacion","alta")
> >   };
> > 
> >   post.setRequestBody(data);
> >   post.setDoAuthentication( true );
> > 
> >   try
> >   {
> >      int status = client.executeMethod( post );
> >      System.out.println(status + "\n" + post.getResponseBodyAsString());
> >   }
> >   catch (HttpRecoverableException e)
> >   {
> >      System.err.println("A recoverable exception occurred, retrying.  "
> > + e.getMessage());
> >   }
> >   catch (IOException e)
> >   {
> >      System.err.println("Failed to download file.");
> >      e.printStackTrace();
> >      System.exit(-1);
> >   }
> >   catch (Exception e)
> >   {
> >      e.printStackTrace();
> >   }
> >   
> >   -------------------
> > 
> >   Has anyone any idea o what I am doing wrong?
> > 
> > Thanks in advance por your help.
> > Iker
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > commons-httpclient-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> > commons-httpclient-dev-help@jakarta.apache.org
> > 
> 
> 
> __________________________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo
> http://search.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
> 


Re: Post and https

Posted by Vamsi Atluri <vk...@yahoo.com>.
Hi Iker,

Actually I have a problem (not so similar) with POST and HTTPS too. I am
trying to establish a connection to a https site and POST some data to it,
but the response is always a null. I am first doing a GET, which works
fine. But then the POST fails. The code I am using is:

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import java.io.*;
import java.security.*;
import java.util.*;

class TestSSLHttpClient
{
	public static void main(String[] args)
	{
		try
		{
			String url = "https://test.abc.com/xyz";
		
			Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
	  		System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");		
			System.out.println("Done setting SSL properties");
			
			HttpClient httpClient = new HttpClient();		
			System.out.println("Got HttpClient: " + httpClient);
		
			GetMethod getMethod = new GetMethod(url);
			System.out.println("Got HttpMethod: " + getMethod);
		
			int statusCode = -1;
		
			statusCode = httpClient.executeMethod(getMethod);
		
			System.out.println("statusCode: " + statusCode);
		
			byte[] responseBody = getMethod.getResponseBody();
			
			String resp = new String(responseBody);
		
			System.out.println("Response: " + resp);
			
			String xmlRequest = "<SomeXML>SomeXML</SomeXML>";
			
			PostMethod postMethod = new PostMethod(url);
			
			postMethod.setRequestBody(xmlRequest);
			
			System.out.println("Built PostMethod: " + postMethod);
			
			statusCode = -1;
			
			statusCode = httpClient.executeMethod(postMethod);
			
			System.out.println("statusCode: " + statusCode);
			
			resp = postMethod.getResponseBodyAsString();
			
			System.out.println("Response: " + resp);
			
			postMethod.releaseConnection();				
		}
		catch(Exception e)
		{
			System.out.println("#######################");
			System.out.println("Error occurred:");
			e.printStackTrace();
			System.out.println("#######################");
		}
	}
}

The error I get is that postMethod.getResponseBodyAsString() is returning
a null. However, if I try to trap the outpup of
postMethod.getResponseBody() into a byte[], I get the following exception:

Error occurred:
java.lang.NullPointerException
        at
org.apache.commons.httpclient.HttpMethodBase.getResponseBody(HttpMeth
odBase.java:670)
        at
org.apache.commons.httpclient.methods.GetMethod.getResponseBody(GetMe
thod.java:293)
        at TestSSLHttpClient.main(TestSSLHttpClient.java:54)

Any help in resolving this would be grately appreciated.

-Vamsi


--- Iker Bilbao <ib...@tid.es> wrote:
> Hello,
> 
>   I am trying to make a post to an https server and I can not make it
>   work. I have what is was in the tutorial for posting but I get the
>   following error:
>             A recoverable exception occurred, retrying. 
> java.net.SocketException: Software caused connection
> abort: JVM_recv in socket input stream read
>   I have retried the operation but it does not work.
> 
>   The GetMehtod works well but not post.
> 
>   Here is my code:
>   -------------------
>   Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
>   System.getProperties().put("java.protocol.handler.pkgs",
> "org.apache.commons.httpclient.HttpClient");
>   System.setProperty("javax.net.ssl.trustStore","C:\\.keystore");
>   System.setProperty("javax.net.ssl.keyStore","C:\\.keystore");
>   System.setProperty("javax.net.ssl.keyStorePassword","password");
> 
>   HttpClient client = new HttpClient();
>   client.getState().setCredentials("Realm",new
> UsernamePasswordCredentials("user","password"));
> 
>   PostMethod post = new PostMethod("https://server:1234"
> +"/gestorpiloto");
>   NameValuePair[] data = {
>     new NameValuePair("tipoOperacion","alta")
>   };
> 
>   post.setRequestBody(data);
>   post.setDoAuthentication( true );
> 
>   try
>   {
>      int status = client.executeMethod( post );
>      System.out.println(status + "\n" + post.getResponseBodyAsString());
>   }
>   catch (HttpRecoverableException e)
>   {
>      System.err.println("A recoverable exception occurred, retrying.  "
> + e.getMessage());
>   }
>   catch (IOException e)
>   {
>      System.err.println("Failed to download file.");
>      e.printStackTrace();
>      System.exit(-1);
>   }
>   catch (Exception e)
>   {
>      e.printStackTrace();
>   }
>   
>   -------------------
> 
>   Has anyone any idea o what I am doing wrong?
> 
> Thanks in advance por your help.
> Iker
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-httpclient-dev-help@jakarta.apache.org
> 


__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com