hei*_*man 11 java apache apache-commons-httpclient apache-httpclient-4.x
如果我想要处理此网址,例如:
post = new HttpPost("http://testurl.com/lists/lprocess?action=LoadList|401814|1");
Run Code Online (Sandbox Code Playgroud)
Java/Apache不会让我,因为它说垂直条("|")是非法的.
用双斜线转义它也不起作用:
post = new HttpPost("http://testurl.com/lists/lprocess?action=LoadList\\|401814\\|1");
Run Code Online (Sandbox Code Playgroud)
^不起作用.
有任何建议如何使这项工作?
Tar*_*ngh 11
尝试 URLEncoder.encode()
注意:你应该编码后面action=没有的字符串complete URL
post = new HttpPost("http://testurl.com/lists/lprocess?action="+URLEncoder.encode("LoadList|401814|1","UTF-8"));
Run Code Online (Sandbox Code Playgroud)
参考http://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html
您必须|在URL中编码为%7C.
考虑使用HttpClient URIBuilder来处理逃逸,例如:
final URIBuilder builder = new URIBuilder();
builder.setScheme("http")
.setHost("testurl.com")
.setPath("/lists/lprocess")
.addParameter("action", "LoadList|401814|1");
final URI uri = builder.build();
final HttpPost post = new HttpPost(uri);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8158 次 |
| 最近记录: |