[英]Android 4.4.2 Kitkat can not send a request with HttpURLConnection
In my app I send a POST request to a server via an HttpURLConnection. 在我的应用程序中,我通过HttpURLConnection将POST请求发送到服务器。 But since I updated my Samsung S4 to Android 4.4.2, I don't receive any requests in the server.
但是,由于我将Samsung S4更新为Android 4.4.2,因此服务器上未收到任何请求。
Here is my code: 这是我的代码:
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 ();
}
}
Am I doing something wrong? 难道我做错了什么? Is there any HttpURLConnection change for KitKat?
KitKat是否有HttpURLConnection更改?
When I use DefaultHttpClient everything works fine and I can receive the request by the server. 当我使用DefaultHttpClient时,一切正常,我可以通过服务器接收请求。 But I still like to use the HttpURLConnection, because the app is testet with this kind of connection.
但是我仍然喜欢使用HttpURLConnection,因为该应用程序具有这种连接方式。
Be aware if you're using emulator. 请注意,如果您使用的是模拟器。 I had such problem as I was using Proxy.
我在使用代理时遇到了这样的问题。 BTW.
顺便说一句。 have you added to your manifest:
您是否已将清单添加到清单中:
<uses-permission
android:name="android.permission.INTERNET"/>
Also to work with response use corresponding class http://developer.android.com/reference/org/apache/http/HttpResponse.html 也可以使用响应使用相应的类http://developer.android.com/reference/org/apache/http/HttpResponse.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.