I am having some difficulties POSTing an json API object that uses REST. I am new to using cURL, but I searched everything to try to find the answer to my problem, but came up with a short one. My cURL request always returns false. I know this is not even a message from my json object, because I still get a response from url. My code is below.
<?php //API KEY = APIUsername //API_CODE = APIPassword $API_Key = "some API key"; $API_Code = "some API code"; $API_email = " email@email.com "; $API_password = "ohhello"; $url = "http://someURL.com/rest.svc/blah"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); header('Content-type: application/json'); $authData = "{\"APIUsername\":\"$API_Key\",\"APIPassword\":\"$API_Code\",\"EmailAddress\":\"$API_email\",\"Password\":\"$API_password\"}"; curl_setopt($ch, CURLOPT_POSTFIELDS, $authData); //make the request $result = curl_exec($ch); $response = json_encode($result); echo $response; curl_close() ?>
$ Response only returns false
Any thoughts?
stekrose
source share