2012-01-04 60 views
0

我需要使用头部参数和表单参数向REST Web服务发出POST请求。我有网络服务方法的描述:REST Web服务POST方法头和表单参数

Method: POST/
Produces: application/json/
Consume: application/x-www-form-urlencoded/and etc. 

和我需要发送的标题和表单参数列表。

任何人都可以澄清什么是生产和消费以及如何形成请求?

As I undestand: httpPost = new HttpPost(webServiceUrl + methodName);

httpPost.setHeader("headerParamName", headerParam); 
    entity = jsonObject.put(param.getKey(), param.getValue());//param - form param 
    httpPost.setEntity(entity); 
    httpPost.setHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF8"); //??? 

对不起,如果问题是假的。

+0

我应该添加一些额外的信息? – user1074896 2012-01-04 09:25:55

回答

2

生成应该是Web服务将返回的数据类型(即它是您的方法将接收的数据的类型),而消费应该是Web服务期望接收的数据的类型(即,您从方法传递的数据)。 所以我认为你必须设置:

httpPost.setHeader("Accept", "application/json"); 
httpPost.setHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF8"); 
+0

http://stackoverflow.com/questions/8727672/how-send-form-params-to-rest-web-service-through-http-client – user1074896 2012-01-04 13:36:16