来自 Google App Engine 的 http 请求
我正在尝试从我的 Google App Engine Web 应用程序发出 http 请求,并发现我必须使用 URLConnection,因为它是唯一列入白名单的类。相应的 Clojure 库是 clojure.contrib.http.agent,我的代码如下:
(defroutes example
(GET "/" [] (http/string (http/http-agent "http://www.example.com")))
(route/not-found "Page not found"))
这在我的开发环境中运行良好 - 浏览器显示 example.com 的文本。但是当我使用 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/
当我加载页面时它就会挂起。没有错误,或者什么。知道会发生什么吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http-agent
创建线程,因此这可能是它不起作用的原因。来自 API 文档< /a>:
您可以尝试 http-connection,它是 HttpURLConnection 的包装器,所以这应该有效。
另一种选择是尝试 clj-http。该 API 似乎更高级一些,但它使用可能被列入黑名单的 Apache HttpComponents。
我猜测 http.async.client 由于其强大的异步性而绝对不能使用方法。
http-agent
creates threads so that might be why it does not work.From the API documentation:
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.
您可能想尝试从 appengine-clj 中使用 appengine.urlfetch/fetch (http://github.com/r0man/appengine-clj,也在 clojars 中)
You might want to try appengine.urlfetch/fetch from appengine-clj (http://github.com/r0man/appengine-clj, also in clojars)