开发者

How to add json to the body of an http post in java

开发者 https://www.devze.com 2023-03-06 07:38 出处:网络
I\'m trying to post some JSON data in java for an Android app I\'m working on. Is the below valid or do开发者_如何学运维 I need to push the JSON string in a different way?

I'm trying to post some JSON data in java for an Android app I'm working on. Is the below valid or do开发者_如何学运维 I need to push the JSON string in a different way?

HttpPost httpost = new HttpPost("http://test.localhost");
httpost.setEntity(new StringEntity("{\"filters\":true}"));
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
//... other java code to execute the apache httpclient

Thank you in advance


You should set the Content-Type header to "application/json". Everything else looks good.

0

精彩评论

暂无评论...
验证码 换一张
取 消