php怎么访问接口
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怎么访问接口的详细内容,更多请关注教程集其它相关文章!
您可能感兴趣的文章:
php别人做好了接口怎么去调用
php怎么测试接口运行慢
带入gRPC:让你的服务同时提供 HTTP 接口
php怎么访问接口
怎么打开php文件
PHP怎么返回一个数据给前台
PHP开发api接口安全验证
php控制器不存在
php怎么默认打开index
php后缀怎么打开