我使用此代码从网页中读取数据:从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