0

java.lang.IllegalArgumentException: Illegal character in query at index 49: http://download.finance.yahoo.com/d/quotes.csv?s=?^NDX,^BANK&f=nsl1opc1

im getting the malformed url exception on the 'caret' (^) symbol..came to know that the caret is used heavily in regex and in other cases this character is particularly removed from a desired string.

Is this not possible to have strings/urls with 'caret' (^) symbol

In the above case to retrieve index data i need to have that symbol..

3

1 Answer 1

2

It is indeed not legal to have a caret in a query string part.

Use the constructor for URI instead:

final URL url = new URI("http", "download.finance.yahoo.com", "/d/quotes.csv",
    "s=?^NDX,^BANK&f=nsl1opc1", null).toURL();

This will take care of all the necessary encoding issues for you.

See the Javadoc.

Sign up to request clarification or add additional context in comments.

2 Comments

Well, there is no reason why it should not work. Try it and see ;)
Side note: if you have many URLs to build that way, one project of mine may be useful: github.com/fge/uri-template

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.