我正在编写一个java应用程序,它向服务器发出http请求并解析响应html和错误页面。我需要从请求中获取错误响应页面。请原谅我,如果我问的问题很简单,我是java新手我主要编程Coldfusion,Javascript,Flash和我使用一点C#。这是我的代码
package com.http.req;
import java.net.*;
import java.io.*;
public class URLConnectionReader {
public static void main(String[] args) throws Exception {
String s1 = getInput();
URL webpage = new URL(s1);
URLConnection yc = webpage.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc
.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
public static String getInput() {
BufferedReader url = new BufferedReader(
new InputStreamReader(System.in));
System.out.flush();
try {
return url.readLine();
} catch (Exception e) {
return "Error";
}
}
}
我需要它来返回从http请求生成的Coldfusion Error页面。当正确写入coldfusion代码时,url.readline()返回html, 如何让它读取错误页面?