Пытаюсь сделать запрос на веб сервер возвращается 405, с веб ресурсом проблем точно нет.
private class AsyncTaskRunner extends AsyncTask<String,String,String>{
@Override
protected String doInBackground(String... params) {
try {
String url="Адрес сайта";
URL object=new URL(url);
HttpURLConnection con = (HttpURLConnection) object.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
con.setRequestMethod("POST");
JSONObject cred = new JSONObject();
cred.put("name","my_name");
DataOutputStream localDataOutputStream = new DataOutputStream(con.getOutputStream());
localDataOutputStream.writeBytes(cred.toString());
localDataOutputStream.flush();
localDataOutputStream.close();
int responseCode = con.getResponseCode();
System.out.println("POST Response Code :: " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) { //success
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// print result
System.out.println(response.toString());
} else {
System.out.println("POST request did not work.");
}
}
catch (Exception e){
Log.v("ErrorAPP",e.toString());
}
return "";
}