Home>Article>Backend Development> Detailed explanation of php get and post methods using curl to call interface methods

Detailed explanation of php get and post methods using curl to call interface methods

伊谢尔伦
伊谢尔伦 Original
2017-07-03 10:33:46 3068browse

The first is the client execution method ApiModel.php:

 $v ) { $o.= "$k=" . urlencode( $v ). "&" ; } $post_data = substr($o,0,-1); $key=md5(base64_encode($post_data)); if($ispost){ $url=$url; }else{ $url = $url.'?'.$post_data; } $curlPost = 'key='.$key; header("Content-type: text/html; charset=utf-8"); $ch = curl_init();//初始化curl curl_setopt($ch, CURLOPT_URL,$url);//抓取指定网页 curl_setopt($ch, CURLOPT_HEADER, 0);//设置header curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上 if($ispost){ curl_setopt($ch, CURLOPT_POST, 1);//post提交方式 curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); } $data = curl_exec($ch);//运行curl curl_close($ch); return $data; } ?>

The client calls the method. You can configure basic information here api.php:

Server's Interface function test.php:

'huanglu','password'=>'123456'); echo json_encode($arr); }else{ exit('非法访问!'); } } serverapi(); ?>

The above is the detailed content of Detailed explanation of php get and post methods using curl to call interface methods. 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