3

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

Here is the exception.

java.io.IOException: Malformed ipv6 address: [10.0.2.2:8888]

Why it said that? Could someone help me? Thanks in advance.

cht
  • 367
  • 2
  • 6
  • 20

2 Answers2

5

Its a known bug thats fixed in a future release.

http://code.google.com/p/android/issues/detail?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)

EDIT

In your case, it would be

URL url = new URL("http", "10.0.2.2" , 8888 , "json/rec?user_data=" + user_data + "&friends=" + friends);
Kal
  • 24,724
  • 7
  • 65
  • 65
  • Hi, thanks. I have read URL at JAVA document. And I hava some questions is that when I set the URL this way, so: protocol = http, host = 10.0.2.2, port = 8888, then file = ? – cht Jul 25 '11 at 03:55
0

Probably because the host contains a colon, which it takes to mean this is a numeric IPv6 address