我有网址:http://xxx.xxx.xxx.xxx:yyyy/api/Account/Register
(ip:port)。在浏览器中我可以像POST方法一样没有任何问题。但Android引发了一个例外:
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:在android.os.AsyncTask $ 2.call(AsyncTask.java:288) W / System.err:at java.util.concurrent.FutureTask.run(FutureTask.java:237)W / System.err: 在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)
请求方法为POST
100%。
我创建了一个新连接:
URL url = new URL(urlStr);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
写出参数:
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();
可能是什么问题?