0
我想在一個字符串中包含html實體以及諸如商標和版權符號之類的奇怪字符,以便在java中使用BasicNameValuePair的值。當我嘗試執行它時,現在默默地失敗。代碼: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中執行這種類型的字符串