在java中发送XML http请求
有人知道我可以用什么来代替StringRequestEntity(),因为它已经被弃用了在java中发送XML http请求,java,xml,apache,http,xmlhttprequest,Java,Xml,Apache,Http,Xmlhttprequest,有人知道我可以用什么来代替StringRequestEntity(),因为它已经被弃用了 PostMethod post = new PostMethod("my endpoint url bla bla bla"); post.setRequestHeader("Content-Type", "text/xml;charset=UTF-8"); String xmlRequest = new String(sw_reg.toString()); log.info("Setting reques
PostMethod post = new PostMethod("my endpoint url bla bla bla");
post.setRequestHeader("Content-Type", "text/xml;charset=UTF-8");
String xmlRequest = new String(sw_reg.toString());
log.info("Setting request body to [" + xmlRequest + "]");
//Send the request
post.setRequestEntity(new StringRequestEntity(xmlRequest));
httpclient.executeMethod(post);
根据文档(找到的),您应该使用以下构造函数
public StringRequestEntity(String content,
String contentType,
String charset)
throws UnsupportedEncodingException
创建具有给定内容、内容类型和类型的新实体
查塞特
因此,您只需要将内容类型和字符集作为额外参数添加到构造函数调用中。参数说明如下
内容-要设置的内容
内容类型-内容的类型,
或空。getContentType()返回的值。如果此内容类型
包含一个字符集,且字符集参数为null,则内容的
将使用类型字符集
字符集-内容的字符集,或
无效的用于将内容转换为字节。如果内容类型为
不包含字符集且字符集不为null,则该字符集将
可以附加到内容类型
我投了反对票,因为问这个问题并不能真正表明研究的努力。不推荐使用的构造函数Javadoc指向您问题的答案。