我正在尝试将包含 html 实体以及商标和版权符号等奇数字符的字符串传递给 java 中 BasicNameValuePair 的值。当我尝试执行它时,现在静默失败。代码:
HttpPost httpPost = new HttpPost("http://localhost:8983");
String test = "<field name=\"description\">Example®<ul><li> This is a bunch of stuff I would like to post</li></ul></field>
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
nvps.add(new BasicNameValuePair("stream.body", test)); // HERE is the string
nvps.add(new BasicNameValuePair("commit","true"));
try {
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
}
HttpResponse response;
try {
response = httpClient.execute(httpPost);
} catch (IOException ex) {
ex.printStackTrace();
}
我认为 "& 符号会导致问题,因为它们可能是 URL 必须单独处理的查询字符。如何在 URL 中执行这种类型的字符串?