dongquan0024 2014-09-30 12:29
浏览 47
已采纳

目前php curl header set

I'm trying to make a post request to salesforce "api". however it accepts only content type which is explicitly set to "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"

The same parameters I send using postman (with the correct header) actually works.

  • 写回答

1条回答 默认 最新

  • dongyuqie4322 2014-09-30 12:56
    关注

    When CURLOPT_POST is true, curl sets Content-Type of the request to application/x-www-form-urlencoded automatically; 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().

    I suspect your problem has nothing to do with the request headers but with how curl handles https. Setting these in your curl_setopt_array() should help:

    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => 2,
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 求一下解题思路,完全不懂。
  • ¥30 关于#硬件工程#的问题:求一下解题思路
  • ¥15 运筹学对偶单纯行法构造扩充问题
  • ¥20 XP系统的老电脑一开机就提示找不到rundll.exe,付费求解
  • ¥15 milvus查询出来的score怎么转换成0-1之间的相似性
  • ¥15 多ip服务器站群如何搭建l2tp服务器
  • ¥15 lvgl V9移植到linux开发板
  • ¥15 VB.net中在窗体中创建一个button控件来关闭窗体,但是提示错误,我该怎么办
  • ¥15 网上下载好的程序但是arduinoIDE编程报错,运行不了,哪里出错了,能具体给改一下吗
  • ¥15 Sharepoint JS开发 付费技术指导