java类中访问web网站

我在java类中用
URL url = new URL("http://search1.mapabc.com/sisserver?highLight=false&config=SPAS&ver=2.0&resType=json&enc=utf-8&spatialXml=%3C?xml%20version=%221.0%22%20encoding=%22gb2312%22?%3E%0D%0A%3Cspatial_request%20method=%22searchPoint%22%3E%3Cx%3E118.46%3C/x%3E%3Cy%3E32.03%3C/y%3E%3Cxs/%3E%3Cys/%3E%3CpoiNumber%3E10%3C/poiNumber%3E%3Crange%3ENaN%3C/range%3E%3Cpattern%3E1%3C/pattern%3E%3CroadLevel%3E0%3C/roadLevel%3E%3Cexkey/%3E%3C/spatial_request%3E%0D%0A&a_k=b0a7db0b3a30f944a21c3682064dc70ef5b738b062f6479a5eca39725798b1ee300bd8d5de3a4ae3");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setRequestMethod("GET");
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line;
while((line=br.readLine())!=null) {
System.out.println(line);
}
访问这个网站
为什么会报Exception in thread "main" java.net.MalformedURLException: Illegal character in URL
at sun.net.www.http.HttpClient.getURLFile(HttpClient.java:592)
at sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:363)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1070)
at com.mitian.interaction.util.MapAbcUtil.main(MapAbcUtil.java:47)
这个错误呢

2个回答

public class MalformedURLExceptionextends IOException

抛出这一异常指示出现了错误的 URL。或者在规范字符串中找不到任何合法协议,或者无法解析字符串。

api上滴,具体原因,等牛人解答...

:arrow:

[code="java"]
{"message":"ok","SpatialBean":{"crossPoiList":[{"name":"绾洓璺?缁忎竴鍗楄矾","y":"32.031027","x":"118.459293"}],"District":{"bounds":"118.364631652832;31.8412818908691;118.770324707031;32.2532577514648","name":"娴﹀彛鍖?,"code":"320111","y":"32.0473","x":"118.567"},"roadList":[{"id":"00257130","distance":"124.248177","level":"45000","direction":"WestSouth","width":"8","name":"绾洓璺?,"ename":"Weisi Road"},{"id":"002533918","distance":"125.279106","level":"45000","direction":"WestSouth","width":"4","name":"缁忎竴鍗楄矾","ename":"(unnamed road)"},{"id":"0025254","distance":"447.719482","level":"52000","direction":"WestSouth","width":"8","name":"602鍘块亾","ename":"602 County Road"},{"id":"00258","distance":"558.714539","level":"52000","direction":"WestSouth","width":"8","name":"601鍘块亾","ename":"601 County Road"},{"id":"002533832","distance":"780.993958","level":"45000","direction":"EastNorth","width":"4","name":"缁忎笁鍗楄矾","ename":"Jing San South Road"}],"Province":{"name":"姹熻嫃鐪?,"code":"320000"},"poiList":[{"icon":"","gridcode":"4818033621","direction":"WestSouth","tel":"","en_name":"","extid":"","xml":"","type":"鍦板悕鍦板潃淇℃伅;浜ら?鍦板悕;閬撹矾鍚?,"url":"","id":"","citycode":"025","timestamp":"","distance":"357","buscode":"","pguid":"B00190AYAO","address":"","en_type":"","name":"缁忎竴鍗楄矾","en_address":"","match":"10","srctype":"basepoi","y":"32.032458","x":"118.457542"},{"icon":"","gridcode":"4818033611","direction":"WestSouth","tel":"","en_name":"","extid":"","xml":"","type":"鍦板悕鍦板潃淇℃伅;琛屾斂鍦板悕;鏉戝簞绾у湴鍚?,"url":"","id":"","citycode":"025","timestamp":"","distance":"268","buscode":"","pguid":"B00190A7DD","address":"","en_type":"","name":"钀藉簞","en_address":"","match":"10","srctype":"basepoi","y":"32.030395","x":"118.457189"}],"City":{"name":"鍗椾含甯?,"telnum":"025","code":"320100"}}}

[/code]

我试了下 是好的啊
中文乱码是因为我的操作系统是英文的原因

立即提问
相关内容推荐