2013-07-26 285 views
0

我想在一個字符串中包含html實體以及諸如商標和版權符號之類的奇怪字符,以便在java中使用BasicNameValuePair的值。當我嘗試執行它時,現在默默地失敗。代碼:BasicNameValuePair字符轉義

HttpPost httpPost = new HttpPost("http://localhost:8983"); 
String test = "<field name=\"description\">Example®&lt;ul&gt;&lt;li&gt; This is a bunch of stuff I would like to post&lt;/li&gt;&lt;/ul&gt;</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中執行這種類型的字符串

回答