private class HttpPostTask extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
HttpURLConnection mHttpCon = null;
String result = null;
try {
mHttpCon = (HttpURLConnection) ((new URL("http://192.168.1.4:8888/about")
.openConnection()));
mHttpCon.setDoOutput(true);
mHttpCon.setRequestProperty("Content-Type", "application/json");
mHttpCon.setRequestMethod("POST");
mHttpCon.connect();
OutputStream mOS = mHttpCon.getOutputStream();
BufferedWriter mWriter = new BufferedWriter(new OutputStreamWriter(mOS, "UTF-8"));
mWriter.write("{'username':'test','fcmid':'fdjslkfjds09f'}");
mWriter.flush();
mWriter.close();
mOS.flush();
mOS.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
我正在使用上面显示的代码,据我所知,它根本没有发送 。 Wireshark甚至没有显示我运行应用程序的手机的IP地址发送的任何内容。我可以收到iOS应用程序的请求,但甚至无法从Android发送任何内容。难道我做错了什么?我查看的所有教程都使用了HttpClient或AndroidHttpClient,它们甚至似乎都不再可用。
答案 0 :(得分:0)
@mkocs你要转发好友,因为你必须在android中提出关键权限才能更改持久性结构