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

查看:617
本文介绍了App Engine的URLFetch:http GET在本地工作,但在部署到特定URL上的GAE时不能工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:



本地我的应用程序正常工作。我的HTTP GET返回代码200,最终的URL为: http://vow.mlspin.com/客户端/ index.aspx



我的应用程序的其余部分也很棒。



我将代码部署到GAE服务器(我使用Eclipse插件来完成我的部署),我的应用程序停止工作,因为返回了错误的html页面!
返回的代码仍然是200,但是这个URL现在是(最终的URL): http://vow.mlspin.com/clients/signin.aspx?id=



我的问题是:重定向有问题吗? Google应用引擎服务器是否被列入黑名单?我在这里做错了什么?有没有人遇到过这个?



我发现的最接近的问题是这个: GAE Java的Http GET 我已经实现了这个建议,但它到目前为止还没有用。



提前感谢大家!



其他信息 - >下面是来自同一确切GET请求的HTTPResponse头,一个来自本地部署,另一个来自GAE部署。
$ b 本地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响应Header

 日期:: 2012年4月24日04:11:19 GMT 
服务器:: 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 =新网址(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; $()()()()() \\\
);
}
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)); //错误
log.severe(从请求返回的代码:+ targetResponse.getResponseCode());
log.severe(final URL:+ targetResponse.getFinalUrl());
String result = new String(targetResponse.getContent());
return result.replaceAll(& nbsp;,);


解决方案

几个月前。最终的谜团是网站重定向到自己,并期望看到一些cookie被放回。但是,urlfetch重定向处理不会发送它接收的任何cookie。在本地运行时,urlfetch模拟可能会与cookies有所不同。



如果您无法使用此功能,则可能需要关闭urlfetch中的以下重定向并自行管理重定向和Cookie。


The Problem:

Locally my application works fine. My HTTP GET returns code 200 and a final URL of: http://vow.mlspin.com/clients/index.aspx?

The rest of my application works great too.

When I deploy my code to GAE servers (I use the Eclipse plugin to do my deployment) my application ceases to work because the wrong html page is returned! the return code is still 200, but the URL is now (final URL): http://vow.mlspin.com/clients/signin.aspx?id=

My Question is: Is there a problem with redirects? Are the google app engine servers somehow blacklisted? What am I doing wrong here? Has anyone encountered this before?

The closest question I've found was this one: Http GET from GAE Java I've implemented this suggestion but it hasn't worked for me so far.

Thank you all in advance!

Additional Info -> below are HTTPResponse headers from the same exact GET request, one from the local deployment and the other from the GAE deployment.

Local HTTP Response Headers

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

Deployed HTTP Response Headers

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

How I'm crafting my requests:

First I tried the easy way

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

then I tried to go low level and just use 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();
}

Finally I've also tried to use Google's 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(" ", " ");
}

解决方案

We had something similar here a few months ago. In the end the mystery was that the site redirected to itself and expected to see some cookie it set back. But the urlfetch redirect handling doesn't send any cookies it receives. It's possible that the urlfetch emulation when running locally does something different with cookies.

If you can't get this to work, you may want to turn off redirect following in urlfetch and manage redirects and cookies yourself.

这篇关于App Engine的URLFetch:http GET在本地工作,但在部署到特定URL上的GAE时不能工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆