使用 asynhttpclient 以原始方式发送数据

send data in raw using asynhttpclient

我 posting JSON 原始 Url [URL 我 post 数据到][1]

param is=eventName="countryList"

代码

 private void testApp() {
    try {
        JSONObject jsonParams = new JSONObject();
        jsonParams.put("key", "value");
        StringEntity entity = new StringEntity(new Gson().toJson(jsonParams));
        entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));

        AsyncHttpClient client = new AsyncHttpClient();
        client.post(getApplicationContext(), "url", entity, "application/json", new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
                super.onSuccess(statusCode, headers, response);

                Log.e("good",response.toString());
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);

                Log.e("fail",throwable.toString());
            }
        });


    } catch (Exception e) {

    }

}

error:fail: cz.msebera.android.httpclient.client.HttpResponseException: Internal Server Error

StringEntity entity = new StringEntity(new Gson().toJson(jsonParams));变化 至:**StringEntity stringEntity = new StringEntity(jsonParams.toString());**

并覆盖

 @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);


            }

你的回应return jsonobject 不是数组