代码之家  ›  专栏  ›  技术社区  ›  yayitswei

来自googleappengine的http请求

  •  2
  • yayitswei  · 技术社区  · 15 年前

    我试图从我的googleappengine webapp发出http请求,发现我必须使用URLConnection,因为它是唯一一个被列入白名单的类。相应的Clojure库是clojure.contrib.http,我的代码如下:

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

    这在我的开发环境中运行良好-浏览器显示example.com网站. 但当我用谷歌的开发应用服务器进行测试时:

    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/
    

    它只是挂起当我加载页面。没有错误,或者别的什么。知道会发生什么吗?

    2 回复  |  直到 15 年前
        1
  •  3
  •   ponzao    15 年前

    http-agent 创建线程,这可能就是它无法工作的原因。

    API documentation :

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

    你可以试试 http-connection ,它是HttpURLConnection的包装器,因此应该可以使用。

    clj-http . API似乎更高级,但它使用 Apache HttpComponents

    我在猜 http.async.client

        2
  •  1
  •   Miki Tebeka    15 年前

    推荐文章