开发者

Android: Parsing URL into web service without space character

All I want to do is to send a URL String into my RESTFUL web service with some kind of code like this

URL someURL= new URL("http://myWebService:port/service/"+CharSequence开发者_如何学编程.getText());

Its all going well until I found error with space character in my URL. I found some solution about replacing the space character with %20 which is I already defined with something like this :

URL someURL= new URL("http://myWebService:port/service/"+CharSequence.getText().replace(" ", "%20"));

Everything, again, seems going well until i found that the replace(Char oldChara, Char newChara) function can only replace ONE space character, and not two.

For brief example when I send the CharSequence.getText() with values "We won" there will be no error, but when I change the values into "We won the battles" there will be an error issuing that there are some illegal character sent to my RESTFUL web service.

Any kind of answer will come up with my great thanks and big salute ~Regards~


Use replaceAll instead of replace.
Although, you should really be doing proper URL encoding. You can use URLEncoder.encode
for example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜