bnnoor
bnnoor

Reputation: 696

send curl request with http header

I want send headers with curl to https site to get user info . but nothing return . i change headers but not work :( . but when i use this site for online request work right . below is my code

$api_url = 'https://api.fax.ir/v1/accounts/selfe';
    $accessToken = get_option('faxir_access_token');
    $ch = curl_init($api_url);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Authorization: Bearer '.$accessToken,
        'x-faxir-clientid: '.$this->client_id
    ));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch,CURLOPT_VERBOSE,1);
    $output = curl_exec($ch);
    curl_close($ch);
    echo $output;

I know maybe headers set is incorect but i don know how change header? i googled and test many ways but all not work :( . sorry for my poor english .

Upvotes: 0

Views: 1151

Answers (1)

ajmedway
ajmedway

Reputation: 1492

Further to our comments exchange, you will need to do some debugging - try this, then write what you see in comments below. I will update this answer once I have seen your comment.

$api_url = 'https://api.fax.ir/v1/accounts/selfe';
$accessToken = get_option('faxir_access_token');
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer '.$accessToken,
    'x-faxir-clientid: '.$this->client_id
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_VERBOSE,1);
$output = curl_exec($ch);
echo "Code:".curl_getinfo($ch, CURLINFO_HTTP_CODE)."<br>";
echo "Error Number:".curl_errno($ch)."<br>";
echo "Error String:".curl_error($ch);
curl_close($ch);
echo $output;

OK, thanks for checking - I suggest trying this: https://stackoverflow.com/a/21114601/2429318

Upvotes: 1

Related Questions