Curl not json response in php

后端 未结 2 751
心在旅途
心在旅途 2021-01-27 20:23

not getting response using curl. I have put all solution but did not get response.

$ch = curl_init();
$header = array(\'api_key:xxxxxxx         


        
2条回答
  •  北恋
    北恋 (楼主)
    2021-01-27 21:12

    here we are getting response without echo on the top of the page but we don't need to that type of out put so we have disabled using span tag.

    echo ""; //to hide the curl response
    $ch = curl_init();
    $header = array('api_key:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx','Content-Type: application/json');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
    if($postdata!=""){
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
    }
    $response = curl_exec($ch);
    $info = curl_getinfo($ch);
    $responseBody = json_decode($response);
    print_r($responseBody); 
    echo $response;  // display 1(one)
    curl_close($ch);
    echo "";
    

    and result is : 1

    check full code

提交回复
热议问题