簡體   English   中英

無法在Java中獲取特定的URL

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM