为什么cUrl响应内容包含字符串中的问号的Json数据

时间:2017-09-01 08:27:41

标签: php json http curl response

我正在使用PHP cUrl从url获取json数据。响应没问题,但是某些属性值在字符串中显示问号。为什么会这样? 我有截图:

enter image description here

我现在使用的代码:

$ url =' https://shopee.co.id/api/v1/item_detail/?item_id=71635103&shop_id=2768984';

Method:

public function getProductDetails($url)
{
    $csrftoken = $this->cookies['csrftoken'];
    $cookies   = $this->cookiesString;

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    curl_setopt($ch, CURLOPT_COOKIEFILE, "shopee_cookies.txt");
    curl_setopt($ch, CURLOPT_COOKIEJAR, "shopee_cookies.txt");
    curl_setopt($ch, CURLOPT_ENCODING, '');
    curl_setopt($ch, CURLOPT_POSTFIELDS, '');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLINFO_HEADER_OUT, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Accept: */*',
        'Accept-Encoding: gzip, deflate, br',
        'Accept-Language: en-US,en;q=0.8',
        'Connection: keep-alive',
        'Cookie: ' . $cookies,
        'Host: shopee.co.id',
        'if-none-match-: *;gzip',
        'if-none-match-: *',
        'Referer: https://shopee.co.id/Canon-EOS-70D-Kit-18-200mm-IS-Built-In-Wifi-i.2768984.71635103',
        'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0',
        'x-api-source: pc',
        'x-requested-with: XMLHttpRequest',
        )
    );

    //echo '<pre>' . print_r($headerSent, 1);

    $result = curl_exec($ch);

    curl_close( $ch );

    return $result;
}

我希望你们帮助我解决这个问题。谢谢。 :)

=============================================== =================  我得到了解决方案......

我已使用&#34; OPTIONS&#34;更改了请求方法 这解决了我的问题......

1 个答案:

答案 0 :(得分:-1)

尝试设置这样的编码:

curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');