【问题标题】:http request from Google App Engine来自 Google App Engine 的 http 请求
【发布时间】:2011-04-18 13:26:54
【问题描述】:

我正在尝试从我的 Google App Engine 网络应用发出 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/

它只是在我加载页面时挂起。没有错误,或任何东西。知道会发生什么吗?

【问题讨论】:

  • http-agent 是否创建线程?我的理解是 App Engine 不喜欢这些。
  • 嗯,好问题。你知道它是否有非线程版本吗?
  • 你可以试试http-connection richhickey.github.com/clojure-contrib/http.connection-api.html,它似乎是HttpURLConnection 的一个相当低级的包装器。或者只使用URLConnection。午饭后我会尝试看看更多的选择。
  • 我添加了我的 cmets 作为正确答案,但它已经失控了。我还添加了更多可能性供您研究。虽然没有时间测试它们中的任何一个:(

标签: google-app-engine clojure httpwebrequest jvm compojure


【解决方案1】:

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

来自API documentation

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

您可以尝试http-connection,它是 HttpURLConnection 的包装器,所以应该可以。

另一种选择是尝试clj-http。 API 似乎更高级一些,但它使用了可能被列入黑名单的Apache HttpComponents

我猜http.async.client 是绝对不行的,因为它具有强大的异步方法。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多