Curl无法设置header application/json php


curl fail to set header application/json php

我的目标是在我的工作中连接一个私人web服务。我试图连接,但当我设置内容类型到应用程序/json失败并返回null,有人可以帮助吗?这是我的代码:

$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json;charset=UTF-8')
        );
curl_setopt($curl, CURLOPT_VERBOSE, 1);
$fp = fopen(WAREHOUSE . '/errorlogc.txt', 'w');
curl_setopt($curl, CURLOPT_STDERR, $fp);
$json_response = curl_exec($curl);

当我执行这段代码时,它失败了,返回null,没有更多的信息,甚至我为它设置的日志也没有显示任何东西。

修复!问题是,在尝试发送数据到服务器之前,我必须为会话设置一个cookie,所以我从连接上的报头响应中获得cookie,然后发送数据。

thanks for the help