无法在 Java/Apache HttpClient 中使用垂直/管道栏处理 url [英] Cannot process url with vertical/pipe bar in Java/Apache HttpClient
本文介绍了无法在 Java/Apache HttpClient 中使用垂直/管道栏处理 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我想处理这个网址,例如:
If I want to process this url for example:
post = new HttpPost("http://testurl.com/lists/lprocess?action=LoadList|401814|1");
Java/Apache 不允许我,因为它说竖线(|")是非法的.
Java/Apache won't let me because it says that the vertical bar ("|") is illegal.
用双斜线转义它也不起作用:
escaping it with double slashes doesn't work as well:
post = new HttpPost("http://testurl.com/lists/lprocess?action=LoadList\\|401814\\|1");
^ 那也行不通.
对如何使这项工作有任何建议?
Any suggestions how to make this work?
推荐答案
try with URLEncoder.encode()
注意:你应该对action=
之后的字符串进行编码,而不是完整的URL
Note: you should encode string which is after action=
not complete URL
post = new HttpPost("http://testurl.com/lists/lprocess?action="+URLEncoder.encode("LoadList|401814|1","UTF-8"));
参考 http://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html
这篇关于无法在 Java/Apache HttpClient 中使用垂直/管道栏处理 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文