帝国CMS模板大全
www.admin99.cn
www.92cms.cn 帝国CMS模板下载站!,情怀,养站,二次开发!源码需求比较大的一站式会员下载,价更省!!!

php怎么访问接口

通过php模拟post请求即可调用。

php 模拟POST提交的方法:

为了使用PHP的cURL函数,你需要安装libcurl包。 (推荐学习:PHP视频教程)

libcurl目前支持http、https、ftp、gopher、telnet、dict、file和ldap协议。 libcurl同时也支持HTTPS认证、HTTP POST、HTTP PUT、 FTP 上传(这个也能通过PHP的FTP扩展完成)、HTTP 基于表单的上传、代理、cookies和用户名+密码的认证。

Php代码:

$post_data = array(); 
$post_data['clientname'] = "test08"; 
$post_data['clientpasswd'] = "test08"; 
$post_data['submit'] = "submit"; 
$url='http://xxx.xxx.xxx.xx/xx/xxx/top.php'; 
$o=""; 
foreach ($post_data as $k=>$v) 
{ 
$o.= "$k=".urlencode($v)."&"; 
} 
$post_data=substr($o,0,-1); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_URL,$url); 
//为了支持cookie 
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
$result = curl_exec($ch); 

以上就是php怎么访问接口的详细内容,更多请关注Gxl网其它相关文章!

赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《php怎么访问接口》
文章链接:https://www.admin99.cn/8129
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
QQ站长交流群:953950264

登录

找回密码

注册