简体   繁体   English

从 xe 转换器 api 获取数据时出现问题

[英]Having issue in fetching data from xe converter api

Hi i am using XE converter api and need to fetch data from the url, my code so far is嗨,我正在使用 XE 转换器 api,需要从 url 中获取数据,到目前为止我的代码是

$new_url = "https://xecdapi.xe.com/v1/account_info/";
$getData = CurlSendPostRequest($new_url);

print_r($getData);


function CurlSendPostRequest($url)
{
        $ch = curl_init($url);
        $options = array(
                CURLOPT_RETURNTRANSFER => true,         // return web page
                CURLOPT_HEADER         => false,        // don't return headers
                CURLOPT_FOLLOWLOCATION => false,         // follow redirects
               // CURLOPT_ENCODING       => "utf-8",           // handle all encodings
                CURLOPT_AUTOREFERER    => true,         // set referer on redirect
                CURLOPT_CONNECTTIMEOUT => 20,          // timeout on connect
                CURLOPT_TIMEOUT        => 20,          // timeout on response
                CURLOPT_POST            => 1,            // i am sending post data
                CURLOPT_POSTFIELDS     => null,    // this are my post vars
                CURLOPT_SSL_VERIFYHOST => 0,            // don't verify ssl
                CURLOPT_SSL_VERIFYPEER => false,        //
                CURLOPT_VERBOSE        => 1,
                CURLOPT_HTTPHEADER     => array(
                    'account_id:mr.125620728',
                    'api_key:d36edshc876f0p5bjge2jujr45'
                )

        );

        curl_setopt_array($ch,$options);
        $data = curl_exec($ch);
        $curl_errno = curl_errno($ch);

        curl_close($ch);
        return $data;
    }

but i am getting an error Not Found.但我收到错误未找到。 i have tried many functions but invain.我尝试了很多功能,但没有用。 looks like having problem in passing my headers看起来在传递我的标题时有问题

In documentation its written something like this在文档中它写的是这样的

curl –i -u account_id:api_key "https://xecdapi.xe.com/v1/account_info/"

but not getting information但没有得到信息

Thanks谢谢

Regards问候

The switch -u account_id:api_key is to specify a username:password.开关-u account_id:api_key用于指定用户名:密码。 From curl --help来自curl --help

 -u, --user USER[:PASSWORD]  Server user and password

So you need to authenticate as mr.125620728 / d36edshc876f0p5bjge2jujr45所以你需要认证为mr.125620728 / d36edshc876f0p5bjge2jujr45

You haven't specified what authentication schemes the XE API supports, but suppose it's Basic Authentication, then you can use您还没有指定 XE API 支持哪些身份验证方案,但假设它是基本身份验证,那么您可以使用

CURLOPT_USERPWD => $username . ":" . $password

where in your case $username=mr.125620728 and $password=d36edshc876f0p5bjge2jujr45在你的情况下$username=mr.125620728$password=d36edshc876f0p5bjge2jujr45

Also see How do I make a request using HTTP basic authentication with PHP curl?另请参阅如何使用 PHP curl 的 HTTP 基本身份验证发出请求?

I know i am late but below is a working example, Just change your account ID and api Key我知道我迟到了,但下面是一个工作示例,只需更改您的帐户 ID 和 api 密钥

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://xecdapi.xe.com/v1/account_info");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

curl_setopt($ch, CURLOPT_USERPWD, 'apifixer.com7390' . ':' . 'miso4ofghfghfh1jbp733jndg');

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
echo $result;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM