- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在为我的网站构建一个 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] 似乎正在检查这个特定的类,但仍然得到了相同的结果。
然后我创建了一个 php 页面,它只打印 $_POST 来检查我的请求,显然对象的数据是按字面意思发送的。看一看:
Clojure=> (resourcefully/post "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=> (resourcefully/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=> (resourcefully/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", :method "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"}
我不太确定如何进行。有什么建议吗?也欢迎有关调试的一般提示!
谢谢
最佳答案
尝试使用 clojure-apache-http ,全功能 Apache HTTP 库的 Clojure 包装器。它确实支持 multipart/form-data POST。
关于lisp - 如何在 POST 请求中发送文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1509051/
我是一名优秀的程序员,十分优秀!