You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by "Roessner, Timo" <ti...@wincor-nixdorf.com> on 2007/07/18 16:24:01 UTC

Using Post-method but getting "URI to long"?

Hi folks,

 

i have a strange problem:

 

I use the http-client for data transmission between two servlets.

Before that i used HttpUrlConnection. With HttpUrlConnection i could transmit quite large files.

Now i completely converted my application to http-client.

The file transmission still works, but unfortunately only for a very small file size.

 

If i exceed this limited file size (just a few KB) i get the following apache error:

            

request failed: URI too long (longer than 8190)

 

Google now tells me, that this only happens using the "GET" method, because with GET the length of an URL is limited.

 

BUT:

 

I don't use the Get-method, instead i use the post method:

 

 Code:

 

   protected String sendRequest(String urlParams) {

 

      String answer = null;

   

      HttpClient httpClient = new HttpClient();

      

      if(networkParams.isUseProxy()) {

         httpClient.getHostConfiguration().setProxy(networkParams.getProxyHost(), networkParams.getProxyPort());

         logger.info("we DO use a proxy: host:" + networkParams.getProxyHost() + "Port: " + new Integer(networkParams.getProxyPort()).toString());

      }

      if(networkParams.isUseProxyCredentials()) {

         httpClient.getState().setProxyCredentials(

                     new AuthScope(networkParams.getProxyHost(), networkParams.getProxyPort()),

                     new UsernamePasswordCredentials(networkParams.getProxyUserName(), networkParams.getProxyUserPassword()));

      }

      

      String url = networkParams.getRemoteProtocoll() +

                 networkParams.getRemoteDestinationAdress() +

                 ":" +

                 networkParams.getRemoteDestinationPort() +

                 networkParams.getRemoteDestinationPath();

      

      HttpMethod method = new PostMethod(url);

      method.setQueryString(urlParams);

   

      try {

         int statusCode = httpClient.executeMethod(method);

         if (statusCode != HttpStatus.SC_OK) {

            logger.error(OutputConstants.ERR_WRONG_RESPONSE + CommonOutput.LOG_SPACER + statusCode);

            return null;

         }

         answer = method.getResponseBodyAsString();

      } catch (HttpException e) {

         logger.error(e.getMessage());

         logger.error(e);

         return null;

      } catch (IOException e) {

         logger.error(e.getMessage());

         logger.error(e);

         return null;

      }

      finally {   

         method.releaseConnection();

      }

      return answer;

   }

 

 

This code part should be the relevant one:

 

 Code:

            

HttpMethod method = new PostMethod(url);

 

I don't get it, everything seems to be fine as far as i can tell?

 

The Apache configuration can not be the problem, because i didn't change it and when i used HttpUrlConnection with "POST" the transfer of bigger files was no problem. This seems to an http-client problem?

 

Does anybody see whats going wrong here?

 

Beste Grüße / Best Regards,

 

Timo Rössner

 

Wincor Nixdorf International GmbH
Services Division OES
Timo Roessner
Wernerwerkdamm 5 (Gebäude 202 / 7.Flur / Raum 743)
13629 Berlin
Germany
Tel.:  +49 30  5017 2865
Fax.:  +49 30  5017 2872
Mobil:  +49 151 171 573 16
Mail:timo.roessner@wincor-nixdorf.com

 


RE: Using Post-method but getting "URI to long"?

Posted by Roland Weber <RO...@de.ibm.com>.
Hello Timo,

> But isn't it a little bit inconsistent to allow GET-like parameter 
> handling in a POST-method?

Feel free to file a comment about RFC 2616 at the IETF.
I would expect an answer like "isn't it inconsistent to
disable URL query parameters depending on the method?" ;-)

The combination of named parameters in the query string
and a single uploaded file in the body of a POST request
has been useful to some people. Not everybody wants to deal
with multipart MIME message bodies to upload a single BLOB.
Query parameters are handled by the Servlet API, multipart
MIME bodies are not.

cheers,
  Roland


RE: Using Post-method but getting "URI to long"?

Posted by "Roessner, Timo" <ti...@wincor-nixdorf.com>.
Thanks for the hint,

now everything works fine....

But isn't it a little bit inconsistent to allow GET-like parameter handling in a POST-method?

Beste Grüße / Best Regards,
 
Timo Rössner
 
Wincor Nixdorf International GmbH
Services Division OES
Timo Roessner
Wernerwerkdamm 5 (Gebäude 202 / 7.Flur / Raum 743)
13629 Berlin
Germany
Tel.:  +49 30  5017 2865
Fax.:  +49 30  5017 2872
Mobil:  +49 151 171 573 16
Mail:timo.roessner@wincor-nixdorf.com
-----Original Message-----
From: Roland Weber [mailto:ossfwot@dubioso.net] 
Sent: Wednesday, July 18, 2007 4:35 PM
To: HttpClient User Discussion
Subject: Re: Using Post-method but getting "URI to long"?

Hello Timo,

> request failed: URI too long (longer than 8190)
> 
> Google now tells me, that this only happens using the "GET" method,
> because with GET the length of an URL is limited.

If you do it right, it happens only with the GET method.

>       HttpMethod method = new PostMethod(url);
>       method.setQueryString(urlParams);

If you want to post your data in the message body, don't
add it to the URL query string. Add it as parameters.

cheers,
  Roland


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


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


Re: Using Post-method but getting "URI to long"?

Posted by Roland Weber <os...@dubioso.net>.
Hello Timo,

> request failed: URI too long (longer than 8190)
> 
> Google now tells me, that this only happens using the "GET" method,
> because with GET the length of an URL is limited.

If you do it right, it happens only with the GET method.

>       HttpMethod method = new PostMethod(url);
>       method.setQueryString(urlParams);

If you want to post your data in the message body, don't
add it to the URL query string. Add it as parameters.

cheers,
  Roland


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


Re: Socket closed exception with one particular url

Posted by Roland Weber <os...@dubioso.net>.
Saurabh AMBASTA wrote:
> We are monitoring important urls using the httpclient. We are able to get 
> a response from all urls except for one, where we get this exception The 
> URL opens from IE. What could be the problem ?

Hello,

try to make the HttpClient request as similar to the IE request as possible.
We've had a case where the value of User-Agent made the difference, but
some servers also fail if you send multiple cookies in separate headers
instead of folding them into a single one. Tracing SSL is a bit tricky,
but maybe you can use an SSL-enabled server with an echo servlet to check
what headers IE sends.

hope that helps,
  Roland



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


Socket closed exception with one particular url

Posted by Saurabh AMBASTA <sa...@lexmarkpartners-europe.com>.
Hi,

We are monitoring important urls using the httpclient. We are able to get 
a response from all urls except for one, where we get this exception The 
URL opens from IE. What could be the problem ?

[INFO] HttpMethodDirector - Retrying request
java.net.SocketException: Socket closed
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA12275)
        at com.sun.net.ssl.internal.ssl.AppOutputStream.write(DashoA12275)
        at 
java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:67)
        at 
java.io.BufferedOutputStream.flush(BufferedOutputStream.java:125)
        at 
org.apache.commons.httpclient.HttpConnection.flushRequestOutputStream(Unknown 
Source)
        at 
org.apache.commons.httpclient.HttpMethodBase.writeRequest(Unknown Source)
        at org.apache.commons.httpclient.HttpMethodBase.execute(Unknown 
Source)
        at 
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Unknown 
Source)
        at 
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(Unknown 
Source)
        at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown 
Source)
        at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown 
Source)

thanks and regards,
Saurabh Ambasta

Phone : 33 - (0) 2 38 71 1508 
Email : saurabh.ambasta@lexmarkpartners-europe.com