1

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?

Denis Sologub
  • 7,277
  • 11
  • 56
  • 123
  • 1
    This question might be helpful to you: http://stackoverflow.com/questions/5379247/filenotfoundexception-while-getting-the-inputstream-object-from-httpurlconnectio. It seems to imply that your webserver is not responding. Are you sure you're using the correct url? – 0xDEADC0DE Nov 07 '16 at 06:58
  • I didn't try to use `getErrorStream()`. Thank you! It can help really. – Denis Sologub Nov 07 '16 at 07:02
  • Yeah, `getErrorStream()` works perfectly! Thank you once yet! – Denis Sologub Nov 07 '16 at 07:28

0 Answers0