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 John Smith <de...@gmail.com> on 2010/09/17 19:13:03 UTC
Backslash in URL
I couldn't understand why I can't use backslash (%5C) symbol in URL?
I've created file "\mytest.php" in my Linux box and sent request in
Firefox http://localhost/\mytest.php
and everything worked fine.
But when I try use HttpClient I get this error
"java.net.URISyntaxException: Illegal character in path at index"
Browser can send request, HttpClient can't. Why did it happen?
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Backslash in URL
Posted by sebb <se...@gmail.com>.
On 17 September 2010 18:13, John Smith <de...@gmail.com> wrote:
> I couldn't understand why I can't use backslash (%5C) symbol in URL?
>
> I've created file "\mytest.php" in my Linux box and sent request in
> Firefox http://localhost/\mytest.php
> and everything worked fine.
>
> But when I try use HttpClient I get this error
> "java.net.URISyntaxException: Illegal character in path at index"
The Exception name is the clue here.
Try using a valid URL, i.e. encode any invalid characters.
> Browser can send request, HttpClient can't. Why did it happen?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Backslash in URL
Posted by Mike Clark <me...@gmail.com>.
On Fri, Sep 17, 2010 at 11:13 AM, John Smith <de...@gmail.com> wrote:
> I couldn't understand why I can't use backslash (%5C) symbol in URL?
>
> I've created file "\mytest.php" in my Linux box and sent request in
> Firefox http://localhost/\mytest.php
> and everything worked fine.
>
> But when I try use HttpClient I get this error
> "java.net.URISyntaxException: Illegal character in path at index"
> Browser can send request, HttpClient can't. Why did it happen?
Firefox does some "heuristic pre-processing" on URLs to escape invalid
characters for you before sending the request to the server. This is
nice and user-friendly and all, but is fairly lax and not spec
compliant. HttpClient is not a browser emulator and it is not part of
its mission to emulate all the conveniences, features, and quirks that
browser vendors fill their products with.
Anyway, I think you pretty much answered your own question. Use %5C
in the URI instead of the literal backslash character. It is not the
job of the URI class or even HttpClient to escape invalid characters
for you. Perhaps take a look at java.net.URLEncoder as a tool to help
build valid URIs to use as input to HttpClient and related classes.
Mike
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org