I am trying to make a simple GET request to the yesmail api, i have the url which i can paste directly in the browser and it displays the correct information, and also if i add the following code as shown in the brief documentation in the Firefox RESTClient i get the correct response:
GET https://services.yesmail.com/enterprise/subscribers?email=karina@email.co.uk HTTP/1.1
Accept-Encoding: gzip,deflate
User-Agent: Jakarta Commons-HttpClient/3.1
Authorization: Basic xxxxxxxxxxxxx
Host: services.yesmail.com
However, when trying to connect using CURL, i am getting nothing, no HTTP response at all and just a blank page. I am not sure what i am doing wrong? This is what i have:
$url = "https://services.yesmail.com/enterprise/subscribers?email=karina@email.co.uk";
$header[] = "Accept-Encoding: gzip, deflate";
$header[] = "User Agent: Jakarta Commons-HttpClient/3.1";
$header[] = "Authorization: Basic xxxxxxxxxxxxx";
$header[] = "Host: services.yesmail.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header );
curl_setopt($ch, CURLOPT_USERPWD, 'xxxxx:xxxxxxxxxx');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
$response = (curl_exec($ch));
print_r($response);
curl_close($ch);
Am i wrong in thinking that the information i put in to the RESTClient goes into the headers in CURL? This is the first time i have been working with API's so any help appreciated.
update
When using the function file_get_contents
i get the correct response(which for the GET method is just a URL with my unique subscriber number):
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("*******:********")
)
));
$data = file_get_contents('https://services.yesmail.com/enterprise/subscribers?email=karina@email.co.uk', false, $context);
echo $data;
However i really want to get the CURL method working as i will want to be able to add a subscriber.