【问题标题】:curl response is not understandable卷曲响应无法理解
【发布时间】:2019-10-14 23:32:46
【问题描述】:

当我发送 curl 请求以获取 access_token 时,响应或结果是人类无法理解的

当我的身份验证完成后,我的重定向 url 将转移到 list()

public function list()
{
      $url = 'https://login.mailchimp.com/oauth2/token';
      $data = [
        'grant_type' => 'authorization_code',
        'client_id' => 2xxxxx177380,
        'client_secret' => '4b02xxxx21dcd32d5406a7d',
        'redirect_uri' => 'http://127.0.0.1:8000/success',
        'code' => $_GET['code']
        ];
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $response = curl_exec ($ch);
     $err = curl_error($ch);  //if you need
     curl_close ($ch);
     return $response;
    }

这是我得到的结果,重定向链接是:http://127.0.0.1:8000/list?access_token=9be9d4b1d724a0b19c7f4aff677b2b69&expires_in=0 响应:

��VJ-*�/R�R��+K��L�/J-,M-.Q��6�

【问题讨论】:

  • 您可能期望 UTF-8 响应,但不要将其解释为一个
  • 我不知道在这里将响应转换为 UTF-8 形式,redirect_url 也不起作用

标签: laravel api curl oauth-2.0 mailchimp


【解决方案1】:

这有什么改变吗?

curl_setopt($ch, CURLOPT_HTTPHEADER, 'text/plain;charset=UTF-8');
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');

【讨论】:

  • 如果你需要解码 utf-8 你可以使用utf8_decode($string)
  • 收到您的建议后出现此错误:格式错误的 UTF-8 字符,可能编码不正确
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-03
  • 1970-01-01
  • 2020-07-12
相关资源
最近更新 更多