使用curl POST多部分/表单数据的正确方法是什么? [英] What is the right way to POST multipart/form-data using curl?

查看:466
本文介绍了使用curl POST多部分/表单数据的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个语法来发布一个文件以及一些参数:

$ $ $ $ $ codeurl -v -include --formkey1 = value1--form upload = localfilename URL

该文件大小约为500K。首先,我看到发送端的内容长度为254。稍后,服务器响应的内容长度为0.
我在哪里出错?



以下是命令的完整跟踪。

  * Couldn在_netrc文件中找不到主机xxx.xxx.xxx.xxx;使用默认
*关于连接()到xxx.xxx.xxx.xxx端口yyyy(#0)
*尝试xxx.xxx.xxx.xxx ...
*添加句柄: CONN:0x4b96a0
*的添加手柄:发送:0
*的添加手柄:recv的:0
*的Curl_addHandleToPipeline:长度:1个
* - 康涅狄格州0(0x4b96a0)send_pipe:1, recv_pipe:0
*的连接到XXX.XXX.XXX.XXX(xxx.xxx.xxx.xxx)端口YYYY(#0)
*的POST / ZZZZZZ / UploadFile HTTP / 1.1
*的User-Agent:curl / 7.32.0
* Host:xxx.xxx.xxx.xxx:yyyy
* Accept:* / *
* Content-Length:254
*期望:100-继续
*内容类型:multipart / form-data; boundary = ------------------------ 948a6137eef50079
*
* HTTP / 1.1 100继续
* HTTP / 1.1 100继续

* HTTP / 1.1 200 OK
* HTTP / 1.1 200 OK
*服务器Apache-Coyote / 1.1未列入黑名单
*服务器:Apache-Coyote /1.1
*服务器:Apache-狼/ 1.1
*新增的cookie JSESSIONID = C1D7DD042E250211D9DEA82688876F88 域xxx.xxx.xxx.xxx,路径/ ZZZZZ /日到期0
*套装 - Cookie:JSESSIONID = C1D7DD042E250211D9DEA82688876F88;路径= / ZZZZZZ /;
* HttpOnly
* Set-Cookie:JSESSIONID = C1D7DD042E250211D9DEA82688876F88;路径= / ZZZZZZ /;仅Http
*的Content-Type:text / html的;字符集= ISO-8859-1
的Content-Type:text / html的;字符集= ISO-8859-1
*的Content-Length:0
*内容长度:0
*日期:2013年10月1日星期二11:54:24 GMT
*日期:2013年10月1日星期二11:54:24 GMT
* Connection#0 to host xxx.xxx.xxx.xxx left intact


解决方案



  curl -v -F key1 = value1 -F upload = @ localfilename URL 


I used this syntax to post a file along with some parameters:

curl -v -include --form "key1=value1" --form upload=localfilename URL

The file is around 500K in size. First of all, I see content length to be 254 on the transmit side. Later the server response's content length is 0. Where am I going wrong?

Here is the complete trace of the command.

* Couldn't find host xxx.xxx.xxx.xxx in the _netrc file; using defaults
* About to connect() to xxx.xxx.xxx.xxx port yyyy (#0)
*   Trying xxx.xxx.xxx.xxx...
* Adding handle: conn: 0x4b96a0
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x4b96a0) send_pipe: 1, recv_pipe: 0
* Connected to xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx) port yyyy (#0)
* POST /zzzzzz/UploadFile HTTP/1.1
* User-Agent: curl/7.32.0
* Host: xxx.xxx.xxx.xxx:yyyy
* Accept: */*
* Content-Length: 254
* Expect: 100-continue
* Content-Type: multipart/form-data; boundary=------------------------948a6137eef50079
*
* HTTP/1.1 100 Continue
* HTTP/1.1 100 Continue

* HTTP/1.1 200 OK
* HTTP/1.1 200 OK
* Server Apache-Coyote/1.1 is not blacklisted
* Server: Apache-Coyote/1.1
* Server: Apache-Coyote/1.1
* Added cookie JSESSIONID="C1D7DD042E250211D9DEA82688876F88" for domain xxx.xxx.xxx.xxx, path /zzzzz/, expire 0
* Set-Cookie: JSESSIONID=C1D7DD042E250211D9DEA82688876F88; Path=/zzzzzz/;
* HttpOnly
* Set-Cookie: JSESSIONID=C1D7DD042E250211D9DEA82688876F88; Path=/zzzzzz/; HttpOnly
* Content-Type: text/html;charset=ISO-8859-1
Content-Type: text/html;charset=ISO-8859-1
* Content-Length: 0
* Content-Length: 0
* Date: Tue, 01 Oct 2013 11:54:24 GMT
* Date: Tue, 01 Oct 2013 11:54:24 GMT
* Connection #0 to host xxx.xxx.xxx.xxx left intact

解决方案

The following syntax fixes it for you:

curl -v -F key1=value1 -F upload=@localfilename URL

这篇关于使用curl POST多部分/表单数据的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆