好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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网其它相关文章!

查看更多关于php怎么访问接口的详细内容...

  阅读:45次