我用下面的代码发送JSON对象到HTTP服务器。发送JSON对象到HTTP服务器的android
最主要的是,我也送布尔值。
public void getServerData() throws JSONException, ClientProtocolException, IOException {
ArrayList<String> stringData = new ArrayList<String>();
DefaultHttpClient httpClient = new DefaultHttpClient();
ResponseHandler <String> resonseHandler = new BasicResponseHandler();
HttpPost postMethod = new HttpPost("http://consulting.for-the.biz/TicketMasterDev/TicketService.svc/SaveCustomer");
JSONObject json = new JSONObject();
json.put("AlertEmail",true);
json.put("APIKey","abc123456789");
json.put("Id",0);
json.put("Phone",number.getText().toString());
json.put("Name",name.getText().toString());
json.put("Email",email.getText().toString());
json.put("AlertPhone",false);
postMethod.setEntity(new ByteArrayEntity(json.toString().getBytes("UTF8")));
String response = httpClient.execute(postMethod,resonseHandler);
Log.e("response :", response);
}
但其显示的例外行
String response = httpClient.execute(postMethod,resonseHandler);
为
org.apache.http.client.HttpResponseException: Bad Request
任何一个可以帮助我。
什么是'postMethod.setEntity(new ByteArrayEntity(json.toString()。getBytes(“UTF8”)));'for? – hwrdprkns 2011-06-15 14:18:40