How does curl keep the previous 0

Source: Internet
Author: User
 private function _sendRequest($url)    {        $content = "";        if(function_exists('file_get_contents'))        {            $content = @file_get_contents($url);        }        else        {            $ch = curl_init();            curl_setopt($ch, CURLOPT_URL, $url);            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //allow redirects            curl_setopt($ch, CURLOPT_HEADER, false);            $content = curl_exec($ch);            $error = curl_errno($ch);            $info = curl_getinfo($ch);            curl_close($ch);        }        $contenArr = json_decode($content);        if(json_last_error() === JSON_ERROR_NONE)        {            return $contenArr;        }        else        {            return $content;        }    

Directly in the browser knocking back is returned 0001 with this method is 1 so reserved in front of the0

Reply content:

 private function _sendRequest($url)    {        $content = "";        if(function_exists('file_get_contents'))        {            $content = @file_get_contents($url);        }        else        {            $ch = curl_init();            curl_setopt($ch, CURLOPT_URL, $url);            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //allow redirects            curl_setopt($ch, CURLOPT_HEADER, false);            $content = curl_exec($ch);            $error = curl_errno($ch);            $info = curl_getinfo($ch);            curl_close($ch);        }        $contenArr = json_decode($content);        if(json_last_error() === JSON_ERROR_NONE)        {            return $contenArr;        }        else        {            return $content;        }    

Directly in the browser knocking back is returned 0001 with this method is 1 so reserved in front of the0

Json_decode did a good job.
$content was 0001, you Json_decode ($content) to convert it to a value of 1.

Are you sure that Curl was executed, and why not file_get_contents?
Json_decode is used to encode a JSON-formatted string, is it a JSON string, please? Is it surrounded by double quotes?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.