aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes HttpClient Apache Commons Client and remove encoding the url's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "HttpClient Apache Commons Client and remove encoding the url Watch "HttpClient Apache Commons Client and remove encoding the url New topic
Author

HttpClient Apache Commons Client and remove encoding the url's

steve labar
Ranch Hand

Joined: Sep 10, 2008
Posts: 55
Please can someone help me! I'm using the appache commons client and am very pleased. However, the specific use I have i need to make sure that the url's are not encoded so that when i make the request and get back a response from the server the inputs in the url were not encoded and thus are as they were in response.

I have done this

method.setURI(new URI(url, false)); // where false is supposeto not encode the url.

However i think it is still encoding when i execute?

any ideas why?
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8964
    
    9

I don't see a two-argument constructor in java.net.URI. Does this code compile?


[How To Ask Questions On JavaRanch]
steve labar
Ranch Hand

Joined: Sep 10, 2008
Posts: 55
yes, it does compile. It is a class in the apache commons library. Have you ever used this library before? i'm pretty new to it. But don't understand why it is encoding my urls
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8964
    
    9

It's always a good idea to mention the fully-qualified name of a class, just in case of name collision: Tell The Details.
As for your problem, the documentation for org.apache.commons.httpclient.URI says:

public URI(String s, boolean escaped)
. . .
escaped - true if URI character sequence is in escaped form. false otherwise.


I would take that to mean that if you set escaped to false, the class will encode the URI, as it mentions elsewhere:
A URI is always in an "escaped" form, since escaping or unescaping a completed URI might change its semantics.



steve labar
Ranch Hand

Joined: Sep 10, 2008
Posts: 55
Thank you for the response however this is still an issue. When you set it to true it expects you "the client" to have it properly formatted. When it is false you just give it the url and it encodes it for you.

I need to connect with the url not encoded at all. I do vulnerability testing and i need the request/response to be untouched. Just as if a proxy made the request.

any ideas?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

Okay. So don't encode the URL, but tell the constructor that it is encoded. Then (most likely, I'm guessing here) the constructor will not attempt to encode your input.
steve labar
Ranch Hand

Joined: Sep 10, 2008
Posts: 55
that sounds reasonable tried that while ago and got.

org.apache.commons.httpclient.URIException: Invalid query
at org.apache.commons.httpclient.URI.parseUriReference(URI.java:2049)
at org.apache.commons.httpclient.URI.<init>(URI.java:147)
at org.apache.commons.httpclient.HttpMethodBase.getURI(HttpMethodBase.java:265)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:383)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8964
    
    9

It sounds like the class is doing some error checking to keep you honest.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpClient Apache Commons Client and remove encoding the url's