来自Google App Engine的http请求 [英] http request from Google App Engine
问题描述
我尝试从我的Google App Engine webapp发出http请求,并发现我必须使用URLConnection,因为它是唯一的白名单类。对应的Clojure库是clojure.contrib.http.agent,我的代码如下:
(defroutes example
(GET/[](http / string(http / http-agenthttp://www.example.com)))
(route / not-foundPage not found))
这在我的开发环境中正常工作 - 浏览器显示example.com的文本。但是当我用Google的开发应用服务器测试它:
phrygian:example wei $ dev_appserver.sh war
2010 -09-28 14:53:36.120 java [43845:903] [Java CocoaComponent兼容模式]:启用
...
INFO:服务器运行在http:// localhost:8080 /
当我加载页面时它刚刚挂起。没有错误,或任何东西。任何想法可能会发生什么?
http-agent
从 API文档:
创建(并立即返回)代表在新线程中运行的HTTP
请求的代理。
http-connection ,它是HttpURLConnection的一个包装,因此应该工作。
另一种选择是尝试 clj-http 。 API似乎有点高级,但它使用可能被列入黑名单的 Apache HttpComponents 。 p>
我在猜测 http.async.client 由于其强异步方法,a>是一个明确的no-go。
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. The corresponding Clojure library is clojure.contrib.http.agent, and my code is as follows:
(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. But when I test it out with Google's development app server:
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.
From the API documentation:
Creates (and immediately returns) an Agent representing an HTTP request running in a new thread.
You could try http-connection, which is a wrapper around HttpURLConnection, so this should work.
Another alternative is to try clj-http. The API seems to be a bit more high-level, but it uses Apache HttpComponents which might be blacklisted.
I am guessing http.async.client is a definite no-go due to its strong asynchronous approach.
这篇关于来自Google App Engine的http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!