Home  >  Article  >  Backend Development  >  PHP method to obtain the data of the interface URL through curl

PHP method to obtain the data of the interface URL through curl

不言
不言Original
2018-05-31 14:34:392688browse

This article mainly introduces the method for PHP to obtain the data of interfaceURL through curl. It has a certain reference value. Now I share it with you. Friends in need can refer to it

As shown below:

<?php
 $weather = curl_init(); 
      curl_setopt($weather,CURLOPT_URL,"https://api.pc2801.com/cqssc/".time()); 
      curl_setopt($weather, CURLOPT_SSL_VERIFYPEER, false); //如果接口URL是https的,我们将其设为不验证,如果不是https的接口,这句可以不用加
      curl_setopt($weather,CURLOPT_RETURNTRANSFER,true);
      $data = curl_exec($weather); 
      curl_close($weather);     
      $data=json_decode($data,true);//将json格式转化为数组格式,方便使用

?>

The above method of PHP obtaining the data of the interface URL through curl is all the content shared with you. Thank you for reading. For more information, please pay attention to the PHP Chinese website.

Related recommendations:

php sends XML data through curl and obtains XML data

PHP simulates login through CURL and obtains data

The above is the detailed content of PHP method to obtain the data of the interface URL through curl. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn