问题描述
由于要抓取任意两个地点的步行时间,必应API总是间歇性出现503错误,我应该怎么样解决呢?错误提示:ServerreturnedHTTPresponsecode:503forURL:http://dev.virtualearth.net/REST/V1/Routes/Walking?wp.0=38.905551340327094%20-77.03111359990604&wp.1=38.9086%20-77.0323&optmz=distance&key=AqSlFau5pH5z6XUvP_xlaX_NHu1gX8Nl4KjfPHyTOLPGUxhtXUB1xU66XGhIAYQTatsun.net.www.protocol.http.HttpURLConnection.getInputStream(UnknownSource)atcom.bike.tool.WebpageCapture.getODString(WebpageCapture.java:54)atcom.bike.dao.stationRentFormDAO.getRentStationFormList(stationRentFormDAO.java:69)我使用API的代码publicStringgetODString(Stringorigins,Stringdestinations)throwsException{/**wp.0是出发地wp.1是目的地*wp.0=38.90706%20-77.015231&wp.1=38.890461%20-76.988355*/StringstrURL="http://dev.virtualearth.net/REST/V1/Routes/Walking?wp.0=";strURL+=origins+"&wp.1="+destinations+"&optmz=distance&key=AqSlFau5pH5z6XUvP_xlaX_NHu1gX8Nl4KjfPHyTOLPGUxhtXUB1xU66XGhIAYQT";//System.out.println(strURL);URLurl=newURL(strURL);HttpURLConnectionhttpConn=(HttpURLConnection)url.openConnection();InputStreamReaderinput=newInputStreamReader(httpConn.getInputStream(),"utf-8");BufferedReaderbufReader=newBufferedReader(input);Stringline="";StringBuildercontentBuf=newStringBuilder();while((line=bufReader.readLine())!=null){contentBuf.append(line);}Stringjson=contentBuf.toString();returnjson;}
解决方案
解决方案二:
跟进调试一下,估计是路径问题,
解决方案三:
你都说是间隙性了,为什么不加异常判断,有异常了catch到再次发送请求不就行了,都知道通过网络传输有时候是不稳定的,再加上用人家的服务,可能人家服务本身给屏蔽掉了这次请求了。