[英]Not able to fetch particular url in java
我一直在使用以下函数来获取和解析URL。
public static void getPage(String url_string, String page)
{
try
{
URL url = new URL(url_string);
System.out.println(url.getPort() + " " + url.getDefaultPort());
URLConnection conn = url.openConnection();
BufferedReader br =
new BufferedReader(new InputStreamReader(conn.getInputStream()));
BufferedWriter bw = new BufferedWriter(new FileWriter(page));
String line = "";
while((line = br.readLine()) != null)
{
bw.write(line + "\n");
}
bw.close();
br.close();
System.out.println("Page fetched in "+page);
}
catch(Exception e)
{
System.out.println("\nError while fetching the page - ");
e.printStackTrace();
}
}
我称其为-
getPage("http://google.com", "tmp.html");
我能够获取任何类型的URL,但无法获取此特定的URL。
http://www.toysrus.com/storefrontsearch/stores.jsp?skuId=13112916&quantity=1&postalCode=79414&productId=13066123&searchRadius=10000
虽然我们可以在Firefox和Chrome上看到此页面。 它也没有出现在这里:
http://www.rexswain.com/httpview.html
http://google.com
发送HTTP 302状态码,表示该位置不可用(暂时)。 但是您在标题数据中收到一个新位置。
您可以解析答案的标题并从字段location
获取新的URL。 尝试打开此新URL。
您应该始终检查HTTP请求的标头数据。
与drkunibar类似,我会说要检查标题。 您可以在Chrome和Firefox中执行此操作。 在Chrome中,打开“工具”>“ developer_tools”,然后切换到“网络”标签。 然后加载网页。 通过单击请求,您可以检查有关它的所有内容。 如果您没有发现任何奇怪的东西,那么我将尝试在调试器中对其进行检查。 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.