我使用此代碼從網頁中讀取數據:從java中的網頁讀取數據時出錯?
public class ReadLatex {
public static void main(String[] args) throws IOException {
String urltext = "http://chart.apis.google.com/chart?cht=tx&chl=1+2%20\frac{3}{4}";
URL url = new URL(urltext);
BufferedReader in = new BufferedReader(new InputStreamReader(url
.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
// Process each line.
System.out.println(inputLine);
}
in.close();
}
}
的網頁給出了URL中的乳膠碼的圖像。
我得到這個異常:
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 400 for URL: http://chart.apis.google.com/chart?
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at ReadLatex.main(ReadLatex.java:11)
誰能告訴我爲什麼有這個問題,應該是什麼這樣的解決方案?
400指錯誤的請求 - 這意味着請求無法被服務器因爲語法錯誤理解....你嘗試一些其他的網址? – 2012-02-21 09:35:40
你應該逃避你所有的特殊字符,並在URL – 2012-02-21 09:36:37