简体   繁体   English

将cURL命令转换为PHP cURL

[英]Command cURL to PHP cURL

I am trying to convert this part of the command cURL to PHP cURL: 我正在尝试将命令cURL的这一部分转换为PHP cURL:

-H 'Accept: application/json'

to

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 

However adding that causes the CURLOPT_POSTFIELDS to not post. 但是,添加会导致CURLOPT_POSTFIELDS无法发布。

Content-Type and Accept are two different headers. Content-TypeAccept是两个不同的标头。 Instead of setting a the content-type, try this: 代替设置内容类型,请尝试以下操作:

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM