Hi there. I feel like I’m missing something obvious here. My goal is to take a cURL command and be able to execute it using PHP. Not rocket science.
Here’s my cURL command that executes flawlessly:
curl -s -d \
'{
"auth":
{
"RAX-KSKEY:apiKeyCredentials":
{
"username": "username_here",
"apiKey": "apikey_here"}
}
}' \
-H 'Content-Type: application/json' \
'https://identity.api.rackspacecloud.com/v2.0/tokens' | python -m json.tool
Here’s my PHP that fails miserably:
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://identity.api.rackspacecloud.com/v2.0/tokens',
CURLOPT_USERAGENT => 'cURL Request',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
json => $jsonData
),
CURLOPT_CONNECTTIMEOUT => 60,
CURLOPT_HTTPHEADER, array(
Content-Type => 'application/json'
),
CURLOPT_BINARYTRANSFER => 1
));
if(!curl_exec($curl)){
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
By the way, the value of $jsonData is:
{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"username_here","apiKey":"apikey_here"}}}
When I execute this PHP code, I receive an error back, code 415, unsupportedMediaType.
Any idea what I’m doing wrong here?
Thanks!