I have url: http://xxx.xxx.xxx.xxx:yyyy/api/Account/Register
(ip:port). And in the browser I can get it like POST method without any problems. But Android throws an exception:
W/System.err: java.io.FileNotFoundException: http://xxx.xxx.xxx.xxx:yyyy/api/Account/Register W/System.err: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186) W/System.err: at com.contedevel.reserves.utils.RestApi.signUp(RestApi.java:37) W/System.err: at com.contedevel.reserves.activity.RegisterActivity$UserRegistrationTask.doInBackground(RegisterActivity.java:415) W/System.err: at com.contedevel.reserves.activity.RegisterActivity$UserRegistrationTask.doInBackground(RegisterActivity.java:396) W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:288) W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237) W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) W/System.err: at java.util.concurrent.ThreadPoolExecutor$Wo9191rker.run(ThreadPoolExecutor.java:587) W/System.err: at java.lang.Thread.run(Thread.java:841)
A request method is POST
100%.
I create a new connection so:
URL url = new URL(urlStr);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
Write arguments so:
OutputStream os = connection.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
final String body = builder.toString();
writer.write(body);
writer.flush();
writer.close();
os.close();
What could be the problem?