Php 为什么Bit.ly v4 API返回无效的\u内容\u类型\u头?

Php 为什么Bit.ly v4 API返回无效的\u内容\u类型\u头?,php,curl,url-shortener,bit.ly,Php,Curl,Url Shortener,Bit.ly,我犯了一个错误。我用这个卷发: $url = "https://api-ssl.bitly.com/v4/shorten"; $data = array('long_url' => 'http://www.google.com'); $ch = curl_init($url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt(

我犯了一个错误。我用这个卷发:

$url = "https://api-ssl.bitly.com/v4/shorten";
$data = array('long_url' => 'http://www.google.com');

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$header = array('Authorization: Bearer ffaaf96dd9e.........');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$response = curl_exec($ch);
curl_close($ch);
print($response);
我得到的回应是:

HTTP/2 406 
server: nginx
date: Sun, 27 Oct 2019 09:01:26 GMT
content-type: application/json
content-length: 41
strict-transport-security: max-age=31536000; includeSubDomains
x-xss-protection: 1; mode=blockFilter
x-content-type-options: nosniff
x-frame-options: DENY
content-security-policy: default-src 'none
via: 1.1 google
alt-svc: clear

{"message":"INVALID_CONTENT_TYPE_HEADER"}
我用谷歌搜索了这个错误,没有任何帮助。为什么我会犯这个错误?我是否在编码上有任何错误,或者我应该在我的bitly帐户中除了生成令牌之外做些别的事情

编辑:我在谷歌上搜索并在github中找到了这个库:
我添加这个是为了帮助人们搜索相同的问题。

我发现问题在于我必须将json格式的参数发送到bitly,而不是数组格式。我还在github的php中搜索并发现了这个有用的bitly api库:

我在《邮递员》中对此进行了测试,想知道为什么即使我有json头,它也会给出那个错误。事实证明,我必须在Postman中使用“raw”选项,并将请求体作为原始json编写:
{“long_url”:https://example.com/page“}