我遇到了错误。我使用这个 curl :
$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"}
我用谷歌搜索了这个错误,没有帮助。为什么我会收到此错误?我在编码时是否犯了任何错误,或者除了生成 token 外,我还应该在我的 bitly 帐户中做其他事情吗?
编辑:我用谷歌搜索并在 github 中找到了这个库:https://github.com/phplicengine/bitly 我添加这个是为了帮助来这里的人搜索同样的问题。
最佳答案
我发现问题是我必须将 json 格式的参数发送给 bitly,而不是数组格式。我还在 google 上搜索并在 github 的 php 中找到了这个有用的 bitly api 库: https://github.com/phplicengine/bitly
关于php - 为什么 Bit.ly v4 API 返回 INVALID_CONTENT_TYPE_HEADER?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58578197/