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

不言
Release: 2023-03-28 17:16:02
Original
2643 people have browsed it

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格式转化为数组格式,方便使用

?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!