【发布时间】:2016-04-22 15:34:11
【问题描述】:
我有一个休息 http URL,我必须从中提取 XML 响应。当我使用浏览器浏览 URL 时,它会返回 html 内容。我的代码也看到相同的 html 内容而不是 XML 内容。
有没有办法获取 XML 内容而不是 html 内容?在下面的代码中,我只得到 html 响应。但是,如果我检查 chrome 中的邮递员插件,它会显示一个很好的 XML 响应。如何使用我的代码获得相同的响应。
public static void sendURL(String urlValue)throws Exception{
URL oracle = new URL("https://whois.arin.net/rest/asn/AS2639");
URLConnection yc = oracle.openConnection();
yc.setRequestProperty("content-type", "application/xml");
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
}
【问题讨论】: