在Android上使用URL抛出IOException异常:畸形IPv6地址 [英] Use URL on Android throws IOException: Malformed ipv6 address

查看:278
本文介绍了在Android上使用URL抛出IOException异常:畸形IPv6地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要发送的Andr​​oid模拟器到本地主机的网络数据,并获得了一定的成效。

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);

这篇关于在Android上使用URL抛出IOException异常:畸形IPv6地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆