繁体   English   中英

如何将json添加到java中的http帖子的主体

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

我正在尝试在java中为我正在处理的Android应用发布一些JSON数据。 以下是有效的还是我需要以不同的方式推送JSON字符串?

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

先感谢您

您应该将Content-Type标头设置为"application/json" 其他一切看起来都不错。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM