I have a flight book model class. After receiving all required information I want to send all information to the server using POST method. But I always get Status code 500 error. My GET method is working fine. My code is given below.
This method convert model class as JSON and send POST request to WSManager class
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();
}
}
This is my WSManager class
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);
}
});
}
}
onFailure method called always with status code 500
Please help me out. Thank in advance.