Shouldn't it be http://x.com
rather than http:x.com
?
Bu tif you have a really simple URL like that (i.e., with no parameters) you won't need to encode it at all.
However, suppose your URL does contain parameters - e.g., http://x.com?param1=value1¶m2=value2
, then you would encode just the parameter values like this:
String encodedString = "http://x.com?param1=" + EnvoyerSMS.urlEncode(value1) + "¶m2=" + EnvoyerSMS.urlEncode(value2);
...but use a StringBuffer
to concatenate these parts rather than using the +
operator like I have.
NB - The reason you were getting the no ':' in URL
error is because you had erroneously encoded the entire URL, so the :
character was also encoded (into whatever its encoded equivalent is).
If you do System.out.println(encodedString);
you will see what URL your HttpConnection
object is trying to work with.