我想通过LoopJ's AndroidAsyncHttp
将JSON作为POST发送到我的localhost服务器。当我运行时它给出了这个错误
400 - org.apache.http.client.HttpResponseException:错误请求
我发送的JSON数据
{"username":"abraham","email":"abr@gmail.com","password":"123"}
代码
public void invokeWS(JSONObject json) throws UnsupportedEncodingException
{
ByteArrayEntity entity = new ByteArrayEntity(json.toString().getBytes("UTF-8"));
entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
AsyncHttpClient client = new AsyncHttpClient();
client.post(getApplicationContext(), "http://0.0.0.0:8080/WebService/rest/users/insert", entity, "application/json", new JsonHttpResponseHandler(){
我打印了entity
并返回
org.apache.http.entity.ByteArrayEntity@2b701463