eak*_*913 4 java google-app-engine get http
问题:
本地我的应用程序工作正常.我的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
Run Code Online (Sandbox Code Playgroud)
部署的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
Run Code Online (Sandbox Code Playgroud)
我是如何制定我的要求的:
首先,我尝试了简单的方法
Document doc = Jsoup.connect(baseMLSURL).get();
Run Code Online (Sandbox Code Playgroud)
然后我试着去低级别,只使用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(" ", " ")+"\r\n");
}
in.close();
return sb.toString();
}
Run Code Online (Sandbox Code Playgroud)
最后我还尝试使用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(" ", " ");
}
Run Code Online (Sandbox Code Playgroud)
几个月前我们在这里有类似的东西.最后,神秘的是该网站重定向到自己,并期望看到它回来的一些cookie.但urlfetch重定向处理不会发送它收到的任何cookie.在本地运行时,urlfetch仿真可能与cookie有所不同.
如果您无法使用此功能,您可能需要关闭urlfetch中的重定向并自行管理重定向和Cookie.
| 归档时间: |
|
| 查看次数: |
1690 次 |
| 最近记录: |