I am trying to call a URL from Java code in the following way:
userId = "Ankur";
template = "HelloAnkur";
value= "ParamValue";
String urlString = "https://graph.facebook.com/" + userId + "/notifications?template=" +
template + "&href=processThis.jsp?param=" + value + "&access_token=abc123";
I have the following problems in this:
- When I do
println(urlString), I see that theurlStringonly has the value upto and before the first ampersand (&). That is, it looks as:https://graph.facebook.com/Ankur/notifications?template=HelloAnkurand rest of it all (which should have been&href=processThis.jsp?param=ParamValue&access_toke=abc123) gets cut off. Why is that and how can I get and keep the full value inurlString? Does&needs to be escaped in a Java String, and if yes, how to do it? - Notice that I am trying to pass a (relative) URL as a parameter value in this query (the value of
hrefasprocessThis.jsp?param=ParamValue. How can I pass this type of value ofhrefwithout mixing it up with the query of this URL (urlString), which only has three parameterstemplate,hrefandaccess_token? That is, how can I hide or escape?and=? Further, what would I need to do ifvaluewasParam Value(with a space)? - Notice that the
templatehas the valueHelloAnkur(with no space). But if I wanted it to have space, as inHello Ankur, how would I do it? Should I write it asHello%20AnkurorHello Ankurwould be fine? - I need the solution in such a way that
URL url = new URL(urlString)can be created, orurlcan be created viaURI. Please describe your answer up to this point as creating a safe URL is not straight forward in Java.
Thanks!