2011-05-14 6 views
40

में एक http पोस्ट के शरीर में जेसन कैसे जोड़ें, मैं एक एंड्रॉइड ऐप के लिए जावा में कुछ 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 

अग्रिम

उत्तर

41

में धन्यवाद आप "application/json" को Content-Type हैडर स्थापित करना चाहिए। बाकी सब कुछ अच्छा लग रहा है।