本文介绍了PostMethod setRequestBody(String)已弃用 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache Commons HttpClient PostMethod 3.1。

I am using Apache Commons HttpClient PostMethod 3.1.

在PostMethod类中,还有三种设置POST方法请求体的方法:

In the PostMethod class there are also three methods for setting POST method's request body:

setRequestBody(InputStream body)
setRequestBody(String body)
setRequestBody(NameValuePair[] parametersBody);

API


不推荐使用前两种方法。有人知道为什么吗?因为如果我想将XML放入请求主体,NameValuePair对我没有帮助。

NameValuePair API

First two methods are deprecated. Does anybody knows why? Because if I want to put an XML to request body, NameValuePair does not help me.

有人知道解决方法或解决方案吗?

Does anybody knows an workaround or a solution?

推荐答案

javadoc说:

RequestEntity有很多实现者,即:

RequestEntity has a lot of implementors, namely:

ByteArrayRequestEntity,FileRequestEntity,InputStreamRequestEntity,MultipartRequestEntity,StringRequestEntity

使用适合你的那个:


  • 如果您的xml在 String 中,请使用

  • 如果它在文件中,请使用

  • if your xml is in a String, use the StringRequestEntity
  • if it is in a file, use the FileRequestEntity

依此类推。

这篇关于PostMethod setRequestBody(String)已弃用 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-03 06:51