android POST请求使用AsyncHttpClient状态码500错误

时间:2016-01-20 11:30:48

标签: android

我有飞行书模型课。收到所有必需的信息后,我想使用POST方法将所有信息发送到服务器。但我总是得到状态代码500错误。我的GET方法运行正常。我的代码如下。

此方法将模型类转换为JSON并将POST请求发送到WSManager类

private void sendToServer(FlightBook flightBook) 
{
    try
    {
        mProgressDialog = ProgressDialog.show(FlightBookActivity.this, "Please wait ...", "Sending Booking request to server ...", true);
        mProgressDialog.setCancelable(true);
        StringEntity entity = new StringEntity(gson.toJson(flightBook));
        wsManager.post(urlManager.getFlightBookURL(), urlManager.getUserName(), urlManager.getPassword(),null, entity);

    }
    catch(Throwable t)
    {
        t.printStackTrace();
    }
}

这是我的WSManager类

public class WSManager 
{
    private WSResponseListener wsResponseListener;
    private Context context;
    private static final String TAG = "WSManager";

    public void post(final String url, String user, String password, String requester,StringEntity entity) 
    {
        AsyncHttpClient client = new AsyncHttpClient();
        client.addHeader(IConstant.WS_USERNAME, user);
        client.addHeader(IConstant.WS_PASSWORD, password);
        client.addHeader(IConstant.REQUESTER, requester);
        client.setTimeout(600000);


        client.post(context, url, entity, IConstant.WS_POST_JSON_CONTENT_TYPE, new AsyncHttpResponseHandler() 
        {
            @Override
            public void onSuccess(String response) 
            {
                Log.v(TAG, "Post Called Successfully");
                wsResponseListener.success(response);
            }

            @Override
            public void onFailure(int statusCode, Throwable error, String content) 
            {
                wsResponseListener.failure(statusCode, error, content);
            }
        });     
    }
}
始终使用状态代码500

调用onFailure方法

请帮帮我。提前谢谢。

0 个答案:

没有答案