由网友([资深情兽])分享简介:我要发送的Android模拟器到本地主机的网络数据,并获得了一定的成效。I want to send the data on the android emulator to the local host web, and get some results.String temp = "http://10.0.2...
我要发送的Android模拟器到本地主机的网络数据,并获得了一定的成效。
I want to send the data on the android emulator to the local host web, and get some results.
String temp = "http://10.0.2.2:8888/json/rec?user_data=" + user_data + "&friends=" + friends;
URL url = new URL(temp);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setReadTimeout(5000);
InputStreamReader is = new InputStreamReader(urlConnection.getInputStream(), "UTF-8");
String output = "";
while(is.ready()) {
output += is.read();
}
下面是个例外。
java.io.IOException: Malformed ipv6 address: [10.0.2.2:8888]
为什么这么说? 有人能帮助我吗? 先谢谢了。
Why it said that? Could someone help me? Thanks in advance.
推荐答案
它是一个已知的错误,多数民众赞成在将来的版本。
Its a known bug thats fixed in a future release.
HTTP://$c$c.google。 COM / P /安卓/问题/详细信息?ID = 12724
最简单的解决方法是使用不同的构造函数的网址..接受主机名,端口和文件
The easy fix is to use a different constructor to the URL .. the one that accepts hostname, port and file
URL(String protocol, String host, int port, String file)
修改
在你的情况,这将是
URL url = new URL("http", "10.0.2.2" , 8888 , "json/rec?user_data=" + user_data + "&friends=" + friends);
相关推荐
最新文章