了解包含多个Content-Type标头的curl POST请求命令 [英] Understanding curl POST request command that contains multiple Content-Type headers

查看:172
本文介绍了了解包含多个Content-Type标头的curl POST请求命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下curl命令:

curl -v -F 'json={"method":"update_video","params":{"video":{"id":"582984001","itemState":"INACTIVE"},"token":"jCoXH5OAMYQtXm1sg62KAF3ysG90YLagEECDAdlhg.."}}' https://api.somewebservice.com/services/post

产生此输出:

{"method":"update_video","params":{"video":{"id":"55269001","itemState":"INACTIVE"},"token":"jCoXH1sg62KAF3ysG90YLagEECTP16uOUSg_fDAdlhg.."}}' https://api.somewebservice.com/services/post
*   Trying 64.74.101.65...
* Connected to api.somewebservice.com (64.74.101.65) port 443 (#0)
* TLSv1.0, TLS handshake, Client hello (1):
* TLSv1.0, TLS handshake, Server hello (2):
* TLSv1.0, TLS handshake, CERT (11):
* TLSv1.0, TLS handshake, Server key exchange (12):
* TLSv1.0, TLS handshake, Server finished (14):
* TLSv1.0, TLS handshake, Client key exchange (16):
* TLSv1.0, TLS change cipher, Client hello (1):
* TLSv1.0, TLS handshake, Finished (20):
* TLSv1.0, TLS change cipher, Client hello (1):
* TLSv1.0, TLS handshake, Finished (20):
* SSL connection using TLSv1.0 / DHE-RSA-AES256-SHA
* Server certificate:
*    subject: OU=Domain Control Validated; OU=Issued through Somewebservice Inc. E-PKI Manager; OU=COMODO SSL; CN=api.brightcove.com
*    start date: 2015-09-02 00:00:00 GMT
*    expire date: 2016-10-09 23:59:59 GMT
*    subjectAltName: api.somewebservice.com matched
*    issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA
*    SSL certificate verify ok.
> POST /services/post HTTP/1.1
> User-Agent: curl/7.41.0
> Host: api.somewebservice.com
> Accept: */*
> Content-Length: 294
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------5106835c8f9f70f9
>
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Content-Type: application/json;charset=UTF-8
< Content-Length: 943
< Date: Sun, 10 Apr 2016 22:29:23 GMT
< Server: somewebservice
<
* Connection #0 to host api.somewebservice.com left intact
{"result": {"id":55225001,"name":"Taxpayers pay to cover tattoos","adKeys":null,"shortDescription":"Opening statements are set to begin in the trial.","longDescription":null,"creationDate":"1260220396","publishedDate":"12603101609","lastModifiedDate":"1460352526","linkURL":null,"linkText":null,"tags":["Crime","national","wtsp","neo-nazi","court","taxpayers","News","David","john"],"videoStillURL":"http:\/\/bcdownload.net\/wtsp\/35134001\/3508134001_55110080001_59001.jpg?pubId=35134001","thumbnailURL":"http:\/\/bcdownload.edgesuite.net\/wtsp\/87134001\/350134001_55110081001_th-55100159001.jpg?pubId=35084001","referenceId":"7cf007503e2ee37a","length":112106,"economics":"AD_SUPPORTED","playsTotal":248,"playsTrailingWeek":0}, "error": null, "id": null}

上面的输出中有两个"Content-Type"对象:

There are two 'Content-Type' objects in the above output:

> Content-Type: multipart/form-data;

< Content-Type: application/json;charset=UTF-8

根据 docs ,使用 -F 允许卷曲以多部分形式发送数据,但是 json = 是我在文档中找不到的.我假设它正在转换字典/字符串:

According to the docs, using -F allows curl to send data as a multi-part form, but then the json= is something I can't find in the docs. I'm assuming it's converting the dictionary/string:

{"method":"update_video","params":{"video":{"id":"582984001","itemState":"INACTIVE"},"token":"jCoXH5OAMYQtXm1sg62KAF3ysG90YLagEECDAdlhg.."}}

使用JSON?或更准确地说,是在POST请求中添加'Content-Type':'application/json'标头吗?那么,这本质上是具有两个不同标头的POST请求吗?

to JSON? Or more precisely, it's adding the 'Content-Type': 'application/json' header to the POST request? So is this essentially a POST request with two distinct headers?

推荐答案

第一个 Content-Type 标头是客户端 request 标头的一部分,第二个标头是客户端的 request 标头的一部分服务器的 response 标头中的一个.请求和响应由2个CRLF分隔.请求和响应都有各自的内容类型.

The first Content-Type header is part of the client's request header and the second one is part of the server's response header. The request and the response are separated by 2 CRLFs. Request and response each have their own Content-Types.

这篇关于了解包含多个Content-Type标头的curl POST请求命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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