发送带有HTTP标头的curl请求 [英] send curl request with http header

查看:107
本文介绍了发送带有HTTP标头的curl请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将卷曲的标题发送到 https网站以获得用户信息。但是什么也没有回报。我更改标题但不起作用:(。,但是当我使用此站点进行在线请求时,如下所示。是我的代码

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;

我知道标题集可能不正确但是我不知道如何更改标头?我用Google搜索并测试了很多方法,但是都没用:(。对不起我的英语不好。

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 .


  • 顶部代码不返回任何内容。

推荐答案

进一步进行评论交流,您将需要进行一些调试-尝试一下,然后写下您在下面的注释中看到的内容。看到您的评论后,我将更新此答案。

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;






好的,谢谢您的检查-我建议您尝试一下: https://stackoverflow.com/a/21114601/2429318

这篇关于发送带有HTTP标头的curl请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆