通过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怎么访问接口的详细内容。