简体   繁体   English

当前设置的PHP curl标题

[英]php curl header set currently

I'm trying to make a post request to salesforce "api". 我正在尝试向salesforce“ api”发出发布请求。 however it accepts only content type which is explicitly set to "application/x-www-form-urlencoded" 但是,它仅接受明确设置为"application/x-www-form-urlencoded"内容类型

When I do this: 当我这样做时:

curl_setopt_array($ch, array(
                CURLOPT_URL => 'https://www.salesforce.com/servlet/servlet.WebToLead',
                CURLOPT_RETURNTRANSFER => 1,
                CURLOPT_POST => 3,
                CURLOPT_POSTFIELDS => json_encode(array (
                        'first_name' => 'foo',
                        'last_name' => 'faa',
                        'email' => 'my.email@gmail.com',
                        'oid' => '#hash',
                        'recordType' => '#hash'
                )),
                CURLOPT_HTTPHEADER=>array(
                        'Content-type: application/x-www-form-urlencoded'
                )
        ));

        $data = curl_exec($ch);
        $info = curl_getinfo($ch);

The response headers content-type is always: "text/html;charset=UTF-8" 响应标头的内容类型始终为: "text/html;charset=UTF-8"

The same parameters I send using postman (with the correct header) actually works. 我使用邮递员发送的相同参数(具有正确的标题)实际上有效。

When CURLOPT_POST is true , curl sets Content-Type of the request to application/x-www-form-urlencoded automatically; CURLOPT_POSTtrue ,curl自动将请求的Content-Type设置为application/x-www-form-urlencoded you don't need to do that manually. 您无需手动执行此操作。 You can verify that (as well as check all other "outgoing" headers) by setting CURLINFO_HEADER_OUT to true prior to your request, then checking the array returned by curl_getinfo() . 您可以通过在请求之前将CURLINFO_HEADER_OUT设置为true ,然后检查curl_getinfo()返回的数组来验证(以及检查所有其他“传出”标头curl_getinfo()

I suspect your problem has nothing to do with the request headers but with how curl handles https. 我怀疑您的问题与请求标头无关,但与curl处理https的方式无关。 Setting these in your curl_setopt_array() should help: curl_setopt_array()应该会有所帮助:

CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2,

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

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