How to get JSON data from Rest API by PHP Curl?

后端 未结 2 811
悲&欢浪女
悲&欢浪女 2021-01-24 03:18

I have a Rest api which I can access by this url: \"http://127.0.0.1:8000/api/thesis/?format=json\". Now I want to get the JSON data from it. For connecting to the api I tried t

2条回答
  •  伪装坚强ぢ
    2021-01-24 03:52

    I think you should use GET method of curl like this

    $service_url = "http://127.0.0.1:8000/api/thesis/?format=json";
    $curl = curl_init($service_url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    //execute the session
    $curl_response = curl_exec($curl);
    //finish off the session
    curl_close($curl);
    $curl_jason = json_decode($curl_response, true);
    print_r($curl_jason);
    

提交回复
热议问题