Json 理解包含多个内容类型头的curl POST请求命令

Json 理解包含多个内容类型头的curl POST请求命令,json,post,curl,http-headers,Json,Post,Curl,Http Headers,使用以下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","

使用以下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}


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

第一个
内容类型
头是客户端请求头的一部分,第二个是服务器响应头的一部分。请求和响应由2个CRLF分隔。请求和响应都有各自的内容类型。

好的,谢谢您的澄清。因此,使用此curl命令执行的实际POST请求的标题为“Content-Type”:“multipart/form data”
json=
实际上看起来像密钥/值对的key=部分,与您可能习惯于在HTTP
GET
请求中的查询字符串中看到的内容相同。实际上,如果您以这种方式提交,那么值部分(即实际的json数据)应该是url编码的,因为如果json碰巧包含一个符号,您的json就会被截断。以这种方式设计REST API对我来说似乎有点愚蠢,但如果服务器给您一个
200 OK
响应,那我猜你的要求是对的。一个更合理的RESTAPI设计会让你只发布json数据(前面没有
json=
),并且在请求头中有
内容类型:application/json
。哦,你仍然需要做一个HTTP
post
,而不是
GET
,你不需要它是多部分的。将
-F
更改为
-data
。太棒了,感谢今晚所有的帮助,非常感谢!
> Content-Type: multipart/form-data;
< Content-Type: application/json;charset=UTF-8
{"method":"update_video","params":{"video":{"id":"582984001","itemState":"INACTIVE"},"token":"jCoXH5OAMYQtXm1sg62KAF3ysG90YLagEECDAdlhg.."}}