我使用此Url以原始方式发布JSON [URL我将数据发布到] [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) {
}
}
错误:失败:cz.msebera.android.httpclient.client.HttpResponseException:内部服务器错误
答案 0 :(得分:0)
更改 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);
}
您的回复返回jsonobject not array