相关疑难解决方法(0)

如何使用cURL将文件内容作为正文实体发送

我正在使用cURL命令行实用程序将HTTP POST发送到Web服务.我想将文件的内容包含在POST的正文实体中.我已尝试使用-d </path/to/filename>类似信息的其他变体--data </path/to/filename> --data-urlencode </path/to/filename>等...文件始终附加.我需要它作为身体实体.

post curl

180
推荐指数
3
解决办法
14万
查看次数

使用curl POST多部分/表单数据的正确方法是什么?

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

curl -v -include --form "key1=value1" --form upload=localfilename URL
Run Code Online (Sandbox Code Playgroud)

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

这是命令的完整跟踪.

* 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 …
Run Code Online (Sandbox Code Playgroud)

forms post curl

139
推荐指数
3
解决办法
15万
查看次数

使用绝对路径或相对路径在curl请求中发送json文件

只是想知道如何使用-d选项发送curl命令,指定一个文件及其路径,而不是当前目录中的文件.

当我尝试使用本地目录中的json文件测试我的应用程序时,这就是我所得到的.应用程序和我都很高兴:

curl -XPOST -H 'Content-Type:application/json' -d @all_fields.json http://testcomp.lab.net:8080/stats -v -s
* About to connect() to testcomp.lab.net port 8080
*   Trying 10.93.2.197... connected
* Connected to testcomp.lab.net (10.93.2.197) port 8080
> POST /stats HTTP/1.1
> User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
> Host: testcomp.lab.net:8080
> Accept: */*
> Content-Type:application/json
> Content-Length: 2882
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
HTTP/1.1 200 OK
< Content-Length: 0
* Connection #0 to host testcomp.lab.net left intact
* Closing connection #0
Run Code Online (Sandbox Code Playgroud)

当我指定另一个目录中的json文件时,这就是我所得到的 …

rest json curl

27
推荐指数
1
解决办法
4万
查看次数

标签 统计

curl ×3

post ×2

forms ×1

json ×1

rest ×1