• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Apache HttpClient problem, help urgently needed!

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all experts,
I am now using the Apache HttpClient class in package

org.apache.commons.httpclient.*;
org.apache.commons.httpclient.methods.*;


to deal with a site. But it seems the apache package does not allow me to embed japanese query strings in my URL, the exception is always thrown when I am using Japanese in my URL:

**************************************************************
org.apache.commons.httpclient.URIException: escaped query not valid
at org.apache.commons.httpclient.URI.setRawQuery(Unknown Source)
at org.apache.commons.httpclient.URI.setEscapedQuery(Unknown Source)
at org.apache.commons.httpclient.HttpMethodBase.getURI(Unknown Source)
at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source
)
at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source
)
at HttpClientTest.main(HttpClientTest.java:34)
*****************************************************************

the following is the relevant snippet of my code:

*****************************************************************

private static String urlString =
"http://www.excite.co.jp/world/english/?wb_lp=JAEN&before=属性の設定";
PostMethod method = new PostMethod(urlString);
HttpClient client = new HttpClient();
int statusCode = client.executeMethod(method);
// up to this stage I got exception
*****************************************************************

Any help is appreciated and urgently needed! Because otherwise my boss is gonna bounce me off the wall! banghead:

Michael :
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should ask these kind questions from apache mailing list.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From RFC 1738 - Uniform Resource Locators (URL):


2.2. URL Character Encoding Issues
URLs are written only with the graphic printable characters of the
US-ASCII coded character set. The octets 80-FF hexadecimal are not
used in US-ASCII, and the octets 00-1F and 7F hexadecimal represent
control characters; these must be encoded.


You aren't using the US-ASCII character set so chances are that you are throwing up an illegal character. You can encode a String with
java.net.UrlEncoder
 
Michael Zhou
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all of the replies and I will have a try!
 
Michael Zhou
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joe,
I followed your advise as encoding the URL using the java.io.URLEncoder class by invoking URLEncoder.encode(url), now I did not get the previous exception anymore, but while as I was trying to execute the request, another exception is thrown:

************************************************************
java.lang.IllegalArgumentException: host parameter is null
at org.apache.commons.httpclient.HttpConnection.<init>(Unknown Source)
at org.apache.commons.httpclient.HttpConnection.<init>(Unknown Source)
at org.apache.commons.httpclient.SimpleHttpConnectionManager.getConnecti
onWithTimeout(Unknown Source)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(Unknow
n Source)
at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source
)
at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source
)
at HttpClientTest.main(HttpClientTest.java:41)
********************************************************

It seems that the encoded URL can not be properly extracted of the target host parameter (while it was executing httpClient.executeMethod(method)). So confused! Anyway, I would really appreciated more if you can offer more advice.

Michael
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You aren't supposed to encode the entire URL, just the parts that are either not in the US-ASCII charset or contain reserved characters.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Other Open Source Products.

You might also want to take a look at http://faq.javaranch.com/view?EaseUp
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic