When the client wants the server to submit information today, the method and parameters displayed as the title are as follows: the input parameter is http: // 192.168.1.173: 8080/Api/petinfo? Flag = adopt & json = [{"pettype": "100", "petname": "ge"}]
public static InputStream getInputStreamFromUrl(String urlstr){ try { InputStream is = null; HttpURLConnection conn = null; System.out.println("urlstr:"+urlstr); URL url = new URL(urlstr); conn = (HttpURLConnection) url.openConnection(); if (conn.getResponseCode() == 200) { is = conn.getInputStream(); return is; } } catch (Exception e) { System.out.println(e.toString()); } return null; }
Return exception: 09-16 09:32:58. 892: I/System. out (416): java. io. IOException: Malformed ipv6 address: [192.168.1.173: 8080] I am wondering, because if I open the browser of the simulator directly, the above URL can be accessed normally. After the help of friends on the Internet, solved this problem, the source solution connection: http://stackoverflow.com/questions/6811482/use-url-on-android-throws-ioexception-malformed-ipv6-address translation is to use HttpURLConnection directly input url will report the above exception, This is a BUG, it should be corrected in later versions. But if you want to call this method now, use URL url = new URL (protocol, host, port, file). Of course, this method, this source solution also has a small BUG. The file parameter must be prefixed. The correct solution should be: URL url = new URL ("http", "192.168.1.173", "8080", "/Api/petinfo? Flag = adopt & json = [{"pettype": "100", "petname": "ge"}] "); then perform the test and pass.