簡體   English   中英

App Engine的URLFetch:http GET在本地工作,但在特定URL上部署到GAE時則不起作用

[英]App Engine's URLFetch: http GET works locally but not when deployed to GAE on a specific URL

問題:

本地我的應用程序工作正常。 我的HTTP GET返回代碼200和最終URL: http//vow.mlspin.com/clients/index.aspx

我的其他應用程序也很有效。

當我將代碼部署到GAE服務器(我使用Eclipse插件進行部署)時,我的應用程序停止工作,因為返回了錯誤的html頁面! 返回碼仍然是200,但現在是URL(最終URL): http//vow.mlspin.com/clients/signin.aspx?id =

我的問題是:重定向有問題嗎? 谷歌應用程序引擎服務器是否被列入黑名單? 我在這做錯了什么? 有沒有人遇到過這個?

我發現的最接近的問題就是這個: 來自GAE Java的Http GET我已經實現了這個建議,但到目前為止它還沒有對我有用。

謝謝大家!

其他信息 - >以下是來自同一GET請求的HTTPResponse標頭,一個來自本地部署,另一個來自GAE部署。

本地HTTP響應標頭

Date :: Tue, 24 Apr 2012 04:12:32 GMT
Server :: Microsoft-IIS/6.0
X-Powered-By :: ASP.NET
X-AspNet-Version :: 2.0.50727
P3P :: CP="NOI DSP COR NID ADMa OPTa OUR NOR"
Cache-Control :: no-cache
Pragma :: no-cache
Expires :: -1
Content-Type :: text/html; charset=utf-8
Content-Length :: 133704

部署的HTTP響應標頭

date :: Tue, 24 Apr 2012 04:11:19 GMT
server :: Microsoft-IIS/6.0
x-powered-by :: ASP.NET
x-aspnet-version :: 2.0.50727
p3p :: CP="NOI DSP COR NID ADMa OPTa OUR NOR"
cache-control :: private
content-type :: text/html; charset=utf-8
content-length :: 4991
x-google-cache-control :: remote-fetch
via :: HTTP/1.1 GWA

我是如何制定我的要求的:

首先,我嘗試了簡單的方法

Document doc = Jsoup.connect(baseMLSURL).get();

然后我試着去低級別,只使用java.net

private String getHttpFromServer(String url) throws IOException
    log.severe("getting http from: "+ url);
    StringBuilder sb = new StringBuilder();
    URL yahoo = new URL(url);
    URLConnection yc = yahoo.openConnection();
    yc.setRequestProperty("Host", "vow.mlspin.com");
    yc.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");
    BufferedReader in = new BufferedReader(
                            new InputStreamReader(
                            yc.getInputStream()));
    String inputLine;

    while ((inputLine = in.readLine()) != null) {
        sb.append(inputLine.replaceAll("&nbsp", " ")+"\r\n");
    }
    in.close();

    return sb.toString();
}

最后我還嘗試使用Google的URLFetcher

private String getHttpUsingFetchService(String url) throws MalformedURLException, IOException {
    URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
    HTTPResponse targetResponse = fetchService.fetch(new URL(url)); // Error
    log.severe("Code returned from request: "+targetResponse.getResponseCode());
    log.severe("final URL: "+targetResponse.getFinalUrl());
    String result = new String(targetResponse.getContent());
    return result.replaceAll(" ", " ");
}

幾個月前我們在這里有類似的東西。 最后,神秘的是該網站重定向到自己,並期望看到它回來的一些cookie。 但urlfetch重定向處理不會發送它收到的任何cookie。 在本地運行時,urlfetch仿真可能與cookie有所不同。

如果您無法使用此功能,您可能需要關閉urlfetch中的重定向並自行管理重定向和Cookie。

您嘗試訪問的服務需要身份驗證。 嘗試訪問您在新瀏覽器或隱身窗口中發布的第一個網址 - 您將被重定向到第二個網址。 您需要使用您的應用程序執行登錄步驟,然后獲取您發布的cookie並將其發送給所有后續請求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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