java使用httpclient爬取一个网站的时候,请求:String url3="http://sh.58.com/ershoufang/33562546149042x.shtml?amp;params=esfjxpclranxuanctrAB^desc&fzbref=0&entinfo=33562546149042_0&cookie=|||c5/nn1jLReK730pAPL8MAg==&psid=108219688199520000030035316&pubid=29787816&local=2&apptype=0&from=1-list-0&key=&trackkey=33562546149042_17b444ec-825b-41c6-9939-e85c0c1e45e4_20180328143317_1522218797570&fcinfotype=gz";
报错:java.net.URISyntaxException: Illegal character in query
现象:使用浏览器访问是ok的
httpclient报错
原因是:特殊字符问题
解决方式:url转为uri,测试还是报错,最近将uri转成uri.toString才ok
URL url = new URL(strUrl); URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null); System.out.println("uri : "+uri.toString()); HttpGet httpget = new HttpGet(uri.toString());