Php 正确发布到此API

Php 正确发布到此API,php,api,curl,post,Php,Api,Curl,Post,我正试着发到这个。不幸的是,我无法通过身份验证 $apiKey = 'mykey'; $username = 'myuid'; $userKey = 'myuserkey'; $url = 'https://api.thetvdb.com/login?'; $LoginQuery = array('apikey' => $apiKey, 'userkey' => $userKey, 'username'

我正试着发到这个。不幸的是,我无法通过身份验证

$apiKey = 'mykey';
$username = 'myuid';
$userKey = 'myuserkey';
$url = 'https://api.thetvdb.com/login?';
$LoginQuery = array('apikey' => $apiKey,
                    'userkey' => $userKey,
                    'username' => $username
                    );
$postfields = json_encode($LoginQuery);
$urlquery = $url . json_encode($LoginQuery);
p_print("URL: " . $urlquery);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
curl_close($ch);
print_r($json);
答复:

{
  "Error": "Bad Content-Type or charset, expected 'application/json'"
}

我发布的不是json吗?我怎么会做错呢?

您需要将
内容类型设置为
应用程序/json

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

您需要将
内容类型设置为
应用程序/json

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));