Return-Path: Mailing-List: contact commons-httpclient-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-httpclient-dev@jakarta.apache.org Received: (qmail 41224 invoked from network); 21 Apr 2003 18:47:56 -0000 Received: from web11006.mail.yahoo.com (216.136.131.56) by daedalus.apache.org with SMTP; 21 Apr 2003 18:47:56 -0000 Message-ID: <20030421184801.43223.qmail@web11006.mail.yahoo.com> Received: from [63.99.119.20] by web11006.mail.yahoo.com via HTTP; Mon, 21 Apr 2003 11:48:01 PDT Date: Mon, 21 Apr 2003 11:48:01 -0700 (PDT) From: Vamsi Atluri Subject: Re: Post and https To: Commons HttpClient Project In-Reply-To: <9719665281.20030421163117@tid.es> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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"; 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 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