Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java BasicNameValuePair字符转义_Java_Urlencode - Fatal编程技术网

Java BasicNameValuePair字符转义

Java BasicNameValuePair字符转义,java,urlencode,Java,Urlencode,我试图将包含html实体以及商标和版权符号等奇数字符的字符串传入java中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 st

我试图将包含html实体以及商标和版权符号等奇数字符的字符串传入java中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();
}
HttpPost-HttpPost=新的HttpPost(“http://localhost:8983");
String test=“Example®ulli这是我想发布的一堆东西/li/ul
List-nvps=newarraylist();
添加(新的BasicNameValuePair(“stream.body”,test));//这是字符串
添加(新的BasicNameValuePair(“提交”、“真实”);
试一试{
setEntity(新的UrlEncodedFormEntity(nvps));
}捕获(不支持DencodingException ex){
例如printStackTrace();
}
HttpResponse响应;
试一试{
response=httpClient.execute(httpPost);
}捕获(IOEX异常){
例如printStackTrace();
}

我认为“&符号引起了一个问题,因为它们可能是URL必须单独处理的查询字符。如何在URL中执行这种类型的字符串?

检查此链接以处理特殊字符。我想这可能会有帮助

放置在HTML标记中的任意文本通常需要更改,以确保生成的HTML保持有效