Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php怎么访问接口

php怎么访问接口

发布时间:2020-07-27   编辑:www.jquerycn.cn
jquery中文网为您提供php怎么访问接口等资源,欢迎您收藏本站,我们将为您提供最新的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怎么访问接口的详细内容,更多请关注jquery中文网其它相关文章!

  • 本文原创发布jQuery中文网,转载请注明出处,感谢您的尊重!
  • 您可能感兴趣的文章:
    php别人做好了接口怎么去调用
    php怎么测试接口运行慢
    php怎么访问接口
    怎么打开php文件
    PHP怎么返回一个数据给前台
    PHP开发api接口安全验证
    PHP 是怎么接收到请求的?
    python 怎么调用百度地图api
    php怎么改端口
    php后缀怎么打开

    [关闭]