php curl 无法post怎么办
时间:2021-09-24
来源:互联网
标签:
今天PHP爱好者给大家带来php curl无法post的解决办法:1、打开相应的PHP代码文件;2、通过“$post_data = "username=bob&key=12345";$response = http_req(...)”方式提交数据即可。希望对大家有所帮助。

本文操作环境:windows7系统、PHP7.1版,DELL G3电脑
php curl 无法post怎么办?
php curl post提交数据失败解决方法
代码如下:
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怎么办的详细内容,更多请关注php爱好者其它相关文章!
-
如何清除DNS缓存?cmd清理dns缓存命令 时间:2026-01-04 -
电脑显示未识别的网络是什么原因?怎么解决? 时间:2026-01-04 -
网络测试工具iperf3超详细下载、安装、使用教程 时间:2026-01-01 -
Session超时时间设置方法详解 时间:2026-01-01 -
Session超时是什么意思?怎么解决? 时间:2026-01-01 -
集群和负载均衡的区别和联系 时间:2025-12-31
今日更新
-
《霸刀传奇》角色系统介绍
阅读:18
-
无期迷途狂暴职业狂级禁闭者推荐
阅读:18
-
无期迷途诡秘职业狂级禁闭者推荐
阅读:18
-
猎豹蓝月传奇开服时间表
阅读:18
-
《空灵诗篇》卡池抽取建议
阅读:18
-
咸鱼之王张角被动1技能回复机制分析
阅读:18
-
MC大战僵尸20.4.3版本下载地址一览
阅读:18
-
三国冰河时代太学院加点攻略
阅读:18
-
向僵尸开炮小黄鸭联动活动商店兑换推荐
阅读:18
-
【黑神话悟空吉吉国王抢先版】下载安装教程
阅读:18










