When you do a post on the server through Android HttpPost , I get a 405 error. only when part of Android I get this error. Does anyone know why?
My code on Android is:
private class sendSignUpPost extends AsyncTask<String, Void, String> {
ProgressDialog dialog = new ProgressDialog(SignUp.this);
@Override
protected void onPreExecute() {
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.setCancelable(false);
dialog.setMax(100);
dialog.setMessage(getString(R.string.text_check_data));
dialog.show();
checkConnection();
//checkFields();
}
@Override
protected String doInBackground(String... params) {
dialog.setMessage(getString(R.string.text_creating_account));
dialog.setProgress(75);
JSONObject jsonObjSend = new JSONObject();
try {
jsonObjSend.put("action", "signup");
jsonObjSend.put("firstname", FIRSTNAME);
jsonObjSend.put("lastname", LASTNAME);
jsonObjSend.put("email", EMAIL);
jsonObjSend.put("password", PASSWORD);
} catch (JSONException e) {
e.printStackTrace();
}
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://nerd.com.br/");
httppost.setHeader("User-Agent", "br.com.nerd");
httppost.setHeader("Accept", "application/json");
httppost.setHeader("Content-Type", "application/json");
StringEntity se = null;
try {
se = new StringEntity(jsonObjSend.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
httppost.setEntity(se);
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
System.out.println("=============>" + httppost);
} catch (ClientProtocolException e) {
Toast.makeText(getApplicationContext(), R.string.text_check_network, Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
BasicResponseHandler responseHandler = new BasicResponseHandler();
String strResponse = null;
if (response != null) {
try {
strResponse = responseHandler.handleResponse(response);
System.out.println("=============>" + response);
} catch (HttpResponseException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return strResponse;
}