来自 Google App Engine 的 http 请求

发布于 2024-09-25 00:17:56 字数 631 浏览 7 评论 0原文

我正在尝试从我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-10-02 00:17:56

http-agent 创建线程,因此这可能是它不起作用的原因。

来自 API 文档< /a>:

创建(并立即返回)代表 HTTP 的代理
请求在新线程中运行。

您可以尝试 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:

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.

左岸枫 2024-10-02 00:17:56

您可能想尝试从 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文