java - Illegal character in URL -



java - Illegal character in URL -

i error "illegal character in url" in code , don't know why: have token , hash string type.

string currenturl = "http://platform.shopyourway.com" + "/products/get-by-tag?tagid=220431" + "&token=" + token + "&hash=" + hash; httpurlconnection urlconnection = null; bufferedreader reader = null; seek { url url = new url(currenturl); urlconnection = (httpurlconnection) url.openconnection(); urlconnection.setrequestmethod("get"); urlconnection.connect(); [...]

but when wrote :

url url = new url("http://platform.shopyourway.com/products/get-by-tag?tagid=220431&token=0_11800_253402300799_1_a9c1d19702ed3a5e873fd3b3bcae6f8e3f8b845c9686418768291042ad5709f1&hash=e68e41e4ea4ed16f4dbfb32668ed02b080bf1f2cbee64c2692ef510e7f7dc26b");

it's work, can't write order because don't know hash , token because generate them every time. thanks.

from oracle docs on creating urls need escape "values" of url string.

url addresses special characters

some url addresses contain special characters, illustration space character. this:

http://example.com/hello world/ create these characters legal need encoded before passing them url constructor.

url url = new url("http://example.com/hello%20world");

encoding special character(s) in illustration easy there 1 character needs encoding, url addresses have several of these characters or if unsure when writing code url addresses need access, can utilize multi-argument constructors of java.net.uri class automatically take care of encoding you.

uri uri = new uri("http", "example.com", "/hello world/", "");

and convert uri url.

url url = uri.tourl();

as commented see other post uses urlencoder replace offending characters

java url get

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -