String url = "http://maps.googleapis.com/maps/api/directions/xml?origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK&sensor=false";
URL google = new URL(url);
HttpURLConnection con = (HttpURLConnection) google.openConnection();
不錯,我用的BufferedReader打印的內容,我得到403錯誤403錯誤在訪問的URL,但工作在瀏覽器
相同的URL在瀏覽器中正常工作。任何人都可以建議。
下面是如何讀取錯誤流:http://stackoverflow.com/a/9129991/10592你需要調用getErrorStream前connection.getResponseCode()()會工作。 –
@Tim Coope,當你發佈** I **發佈的答案時,這很有趣。 –