我正在尝试从我的 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 的文本。但是当我用谷歌的开发应用程序服务器测试它时:
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
创建线程,这可能就是它不起作用的原因。
来自API文档 http://richhickey.github.com/clojure-contrib/http.agent-api.html#clojure.contrib.http.agent/http-agent:
创建(并立即返回)代表 HTTP 的代理
请求在新线程中运行。
你可以尝试http 连接 http://richhickey.github.com/clojure-contrib/http.connection-api.html,它是 HttpURLConnection 的包装器,所以这应该可以工作。
另一种选择是尝试clj-http http://github.com/clj-sys/clj-http。该API似乎更高级一点,但它使用了Apache HttpComponents http://hc.apache.org/可能会被列入黑名单。
我猜http.async.client http://github.com/neotyk/http.async.client由于其强大的异步方法,这是绝对不行的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)