简体   繁体   English

来自Google App Engine的http请求

[英]http request from Google App Engine

I'm trying to make http requests from my Google App Engine webapp, and discovered I have to use URLConnection since it's the only whitelisted class. 我试图从我的Google App Engine网络应用发出http请求,并发现我必须使用URLConnection,因为它是唯一列入白名单的类。 The corresponding Clojure library is clojure.contrib.http.agent, and my code is as follows: 相应的Clojure库是clojure.contrib.http.agent,我的代码如下:

(defroutes example
  (GET "/" [] (http/string (http/http-agent "http://www.example.com")))
  (route/not-found "Page not found"))

This works fine in my development environment- the browser displays the text for example.com. 在我的开发环境中,这可以正常工作-浏览器显示example.com的文本。 But when I test it out with Google's development app server: 但是,当我使用Google的开发应用服务器进行测试时:

phrygian:example wei$ dev_appserver.sh war
2010-09-28 14:53:36.120 java[43845:903] [Java CocoaComponent compatibility mode]: Enabled
...
INFO: The server is running at http://localhost:8080/

It just hangs when I load the page. 当我加载页面时,它只是挂起。 No error, or anything. 没有错误,还是什么。 Any idea what might be going on? 知道会发生什么吗?

http-agent creates threads so that might be why it does not work. http-agent创建线程,因此可能是为什么它不起作用的原因。

From the API documentation : API文档中

Creates (and immediately returns) an Agent representing an HTTP request running in a new thread. 创建(并立即返回)代表在新线程中运行的HTTP请求的代理。

You could try http-connection , which is a wrapper around HttpURLConnection, so this should work. 您可以尝试http-connection ,它是HttpURLConnection的包装器,因此应该可以使用。

Another alternative is to try clj-http . 另一种选择是尝试clj-http The API seems to be a bit more high-level, but it uses Apache HttpComponents which might be blacklisted. 该API似乎更高级一些,但是它使用了可能被列入黑名单的Apache HttpComponents

I am guessing http.async.client is a definite no-go due to its strong asynchronous approach. 我猜http.async.client由于其强大的异步方法而绝对无法使用。

您可能想尝试从appengine-clj(http://github.com/r0man/appengine-clj,也在clojars中)获取appengine.urlfetch / fetch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Android应用到Google Cloud Engine应用的HTTP请求身份验证 - Authentication of HTTP request from an Android App to A Google Cloud Engine App Google App Engine-http请求/响应 - Google App Engine - http request/response Google App Engine 上的传出 HTTP 请求位置 - Outgoing HTTP Request Location on Google App Engine Google App Engine Python上的异步http请求 - async http request on Google App Engine Python 发出http请求谷歌应用引擎 - Issue http request google app engine 在 Google App Engine 上发送“内部”http 请求 - Send an “internal” http request on Google App Engine 使用Google App Engine中的Firebase进行Google EndPoint身份验证 - HTTP请求中不包含身份验证令牌 - Google EndPoint Authentication with Firebase from Google App Engine - No auth token is contained in the HTTP request Google Cloud Functions http请求仅由Google App Engine提供 - Google Cloud Functions http request only by Google App Engine Google App Engine HTTP - Google App Engine HTTP 如何使用当前经过Google App Engine身份验证的用户从GAE发出http请求 - How can I use the current Google App Engine authenticated user to make a http request from GAE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM