How to Deal with the Urisyntaxexception

How to deal with the URISyntaxException

Use % encoding for the ^ character, viz. http://finance.yahoo.com/q/h?s=%5EIXIC

How to deal with URISyntaxException: Illegal character in path in Hadoop Map Reduce job?

I also faced same exception, I was able to resolve with removing space in foldername where mapper and reducer programs are kept .

URISyntaxException - How to deal with urls with %

Encode also the percent sign with %25.

http://something.com/test/anything 10%-20% 04-03-07 would work with http://something.com/test/anything%2010%25-20%25%2004-03-07.

You should be able to use for example URLEncoder.encode for this - just remember, that you need to urlencode the path part, not anything before that, so something like

String encodedUrl =
String.format("http://something.com/%s/%s",
URLEncoder.encode("test", "UTF-8"),
URLEncoder.encode("anything 10%-20% 04-03-07", "UTF-8")
);

Note: URLEncoder encodes spaces to + instead of %20, but it should work equally well, both are ok.

how to remove java.net.URI syntax exception

As per this link:

http://www.blooberry.com/indexdot/html/topics/urlencoding.htm the Caret ("^") comes under unsafe category.

"Unsafe characters" Why: Some
characters present the possibility of
being misunderstood within URLs for
various reasons. These characters
should also always be encoded.

After changing the ^ to %5E it works.

Now if you copy the url from your browser and put it in another browser then it will work. I think the browser internally takes care of the special characters. But in java the java.net.URL is supposed to work with standalone and console applications and as well on different platforms, therefore, it is the responsibility of the developer to take care of encoding special characters.

Google for java based URL encoders.

java.net.URISyntaxException: Illegal character in scheme name

I think you have some empty spaces before or after https:, you should remove them.

URISyntaxException while concatenating double quotes to a URL

You need to URL encode the query part of the URL.

If the URL should contain a " character, it must be in the form of %22.

Here's some code:

import java.net.URLEncoder;

...

URL += "query=" + URLEncoder.encode(query, StandardCharsets.UTF_8) + "&page=" + page + "&size=" + size;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Update:

If I use [the above suggestion], it gives me Error 500 internal server error

This means that the URL in created properly, and that the request reaches the server. Please post a new question with the server side error if you can't figure that out.

URISyntaxException Illegal character in query

It's because of the whitespace here ...jsp?Type=A Type&..., you can replace it with +

http://www.example.com/engine/myProcessor.jsp?Type=A+Type&Name=1100110&Char=!"


Related Topics



Leave a reply



Submit