php curl 无法post怎么办

php curl无法post的解决办法:1、打开相应的PHP代码文件;2、通过“$post_data = “username=bob&key=12345”;$response = http_req(…)”方式提交数据即可。

php curl 无法post怎么办

本文操作环境:windows7系统、PHP7.1版,DELL G3电脑

php curl 无法post怎么办?

php curl post提交数据失败解决方法

代码如下:

立即学习“PHP免费学习笔记(深入)”;

function http_req($http_type, $method, $url, $data){    $ch = curl_init();    if (strstr($http_type, 'https')) {        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);    }    if ($method == 'post') {        curl_setopt($ch, CURLOPT_POST, 1);        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);    } else {        $url = $url . '?' . $data;    }    curl_setopt($ch, CURLOPT_URL, $url);    curl_setopt($ch, CURLOPT_HEADER, 0);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($ch, CURLOPT_TIMEOUT, 100000);//超时时间    try {        $ret = curl_exec($ch);    } catch (Exception $e) {        curl_close($ch);        return json_encode(array('ret' => 0, 'msg' => 'failure'));    }    curl_close($ch);    return $ret;}  //第一种提交方式在遇到post_data 中包含@等一些符号时会出现提交失败的情况  $url = "http://localhost/web_services.php"; $post_data = array ("username" => "bob","key" => "12345"); $response = http_req('http', 'post', $url, $post_data ); //第二种提交方式可以避免 $url = "http://localhost/web_services.php"; $post_data = "username=bob&key=12345"; $response = http_req('http', 'post', $url, $post_data );   

登录后复制

推荐学习:《PHP视频教程》


登录后复制

以上就是php curl 无法post怎么办的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2108361.html

(0)
上一篇 2025年2月24日 15:18:00
下一篇 2025年2月21日 16:42:17

AD推荐 黄金广告位招租... 更多推荐

相关推荐

发表回复

登录后才能评论