cURL request works in terminal, but when running the request in PHP I get errors
<p>I'm using <a href="http://namechk.com" rel="nofollow">namechk.com</a> API to check if a social media name is available (Twitter). It works fine when I make a cURL request in the terminal, but when running in PHP I get errors.</p>

<p>The following query in the terminal works fine:</p>

<p><code>curl -i -H "AUTHORIZATION: Bearer xxxxxxxxxx" -H "Accept: application/vnd.api.v1+json" -d "site=twitter&amp;username=namechk" "https://api.namechk.com/services/check.json"
</code></p>

<p>Following the docs on namechk.com the following should work (unmodified, taken straight from docs):</p>

<pre><code>&lt;?php

$http_options = array(
    'http' =&gt; array(
        'method' =&gt; 'POST',
        'content' =&gt; json_encode(array('site' =&gt; 'twitter', 'username' =&gt; 'namechk')),
        'header' =&gt; array("AUTHORIZATION: Bearer xxxxxxx".PHP_EOL,    "Accept: application/vnd.api.v1+json".PHP_EOL, "Content-Type: application/json".PHP_EOL)
));

$context = stream_context_create($http_options);
$contents = file_get_contents("https://api.namechk.com/services/check.json", false, $context);
$results = json_decode($contents, true);
</code></pre>

<p>... Except I get an error:</p>

<p><code>Warning: file_get_contents(https://api.namechk.com/services/check.json): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found</code></p>

<p>I write a function using cURL for PHP that returns empty:</p>

<pre><code>public function checkSite($username, $service) {
    $ch = curl_init('https://api.namechk.com/services/check.json');

    $headers = array(
        "AUTHORIZATION: Bearer {$this-&gt;token}",
        "Accept: application/vnd.api.v1+json",
        "Content-Type: application/json"
    );

    curl_setopt_array($ch , array(
        CURLOPT_HTTPHEADER =&gt; $headers,
        CURLOPT_POSTFIELDS =&gt; array(
            'site' =&gt; $service,
            'username' =&gt; $username
        ),
        CURLOPT_RETURNTRANSFER =&gt; true,
        CURLOPT_HEADER =&gt; false,
        CURLOPT_FOLLOWLOCATION =&gt; true
    ));

    $results = curl_exec($ch);
    curl_close($ch);
    return $results;
}
</code></pre>