【发布时间】:2009-10-02 11:45:53
【问题描述】:
我正在为我的网站构建一个 clojure API,它基本上是原始 Web API 的包装器。我无法实现的功能之一是通过 POST 请求发送文件,基本上我会在 shell 中使用 curl -F foo=bar baz=@bak.jpg foobar.com 执行此操作。
我使用的是clojure-http-client,最初尝试了(resourcefully/post "foobar.com" {} {:foo "bar" :baz (File. "bak.jpg")}) 的形式,但是接收脚本忽略了:baz 字段,就好像我只发送了:foo。后来,我尝试将File. 更改为FileInputStream,因为client.clj 的[第51 行][2] 似乎正在检查这个特定的类,但仍然得到相同的结果。
然后我创建了一个简单地打印 $_POST 以检查我的请求的 php 页面,显然对象的数据是按字面意思发送的。看看:
Clojure=> (足智多谋/发布“http://ptchan.org/pttest.php” {} {:foo "bar" :baz "/tmp/bak.jpg"}) {:body-seq ("Array" "(" " [foo] => bar" " [baz] => /tmp/bak.jpg" ")"), :code 200, :msg "OK", :method "POST", :headers {:date ("Fri, 02 Oct 2009 11:41:15 GMT"), :vary ("Accept-Encoding"), :content-length ("53"), :connection ("close "), :content-type ("text/html"), :server ("Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny3 with Suhosin-Patch"), :x-powered-by ( "PHP/5.2.6-1+lenny3")}, :get-header #, :cookies nil, :url "http://ptchan.org/pttest.php"}
Clojure=> (足智多谋/post "http://ptchan.org/pttest.php" {} {:foo "bar" :baz (File."/tmp/bak.jpg")}) {:body-seq ("Array" "(" " [foo] => bar" " [baz] => /tmp/bak.jpg" ")"), :code 200, :msg "OK", :method "POST", :headers {:date ("Fri, 02 Oct 2009 11:41:30 GMT"), :vary ("Accept-Encoding"), :content-length ("53"), :connection ("close "), :content-type ("text/html"), :server ("Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny3 with Suhosin-Patch"), :x-powered-by ( "PHP/5.2.6-1+lenny3")}, :get-header #, :cookies nil, :url "http://ptchan.org/pttest.php"}
Clojure=> (足智多谋/post "http://ptchan.org/pttest.php" {} {:foo "bar" :baz (FileInputStream. "/tmp/bak.jpg")}) {:body-seq ("Array" "(" " [foo] => bar" " [baz] => java.io.FileInputStream@320f6398" ")"), :code 200, :msg "OK", :方法“POST”、:headers {:date (“Fri, 02 Oct 2009 11:41:47 GMT”)、:vary (“Accept-Encoding”)、:content-length (“73”)、:connection (“ close"), :content-type ("text/html"), :server ("Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny3 with Suhosin-Patch"), :x-powered-by ("PHP/5.2.6-1+lenny3")}, :get-header #, :cookies nil, :url "http://ptchan.org/pttest.php"}
我不确定如何继续。有什么建议吗?也欢迎有关调试的一般提示!
谢谢
【问题讨论】: