In Java / Apache httpclient, you cannot use vertical / pipe bars to process URLs
•
Java
If I want to handle this URL, for example:
post = new HttpPost("http://testurl.com/lists/lprocess?action=LoadList|401814|1");
Java / Apache won't let me because it means that the vertical bar ("|) is illegal
You can't escape it with a double slash:
post = new HttpPost("http://testurl.com/lists/lprocess?action=LoadList\\|401814\\|1");
^That won't work
Any suggestions on how to make this work?
Solution
Try using urlencoder encode()
Note: you should encode the string after action = incomplete URL
post = new HttpPost("http://testurl.com/lists/lprocess?action="+URLEncoder.encode("LoadList|401814|1","UTF-8"));
reference resources http://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码