【发布时间】:2014-10-17 09:16:20
【问题描述】:
在我的应用程序中,我通过 HttpURLConnection 向服务器发送 POST 请求。但自从我将三星 S4 更新到 Android 4.4.2 后,我在服务器中没有收到任何请求。
这是我的代码:
private static void send (final String uri, String SomeText) throws IOException {
final URL url = new URL (uri);
final HttpURLConnection conn;
// setup the connection
conn = (HttpURLConnection) url.openConnection ();
conn.setDoInput (true);
conn.setDoOutput (true);
conn.setUseCaches (false);
conn.setRequestMethod ("POST");
conn.setChunkedStreamingMode (0);
final OutputStream os = conn.getOutputStream ();
final OutputStreamWriter osw = new OutputStreamWriter (os);
final BufferedWriter writer = new BufferedWriter (osw);
try {
writer.write (SomeText);
} finally {
writer.flush ();
writer.close ();
conn.disconnect ();
}
}
我做错了吗? KitKat 的 HttpURLConnection 是否有任何更改?
当我使用 DefaultHttpClient 时,一切正常,我可以接收服务器的请求。但是我还是喜欢用HttpURLConnection,因为这个app是testet的这种连接方式。
【问题讨论】:
标签: android http connection android-4.4-kitkat