最近遇到一个很奇怪的问题
在发送post请求时,如果POSTFIELDS的类型为string的话,就会超时,但类型为array就没问题。$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
// 数据为string类型时,超时;
// 如果是array('param' => $data_string)就没问题。
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_exec($ch);
curl_close($ch);
在发送post请求时,如果POSTFIELDS的类型为string的话,就会超时,但类型为array就没问题。$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
// 数据为string类型时,超时;
// 如果是array('param' => $data_string)就没问题。
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_exec($ch);
curl_close($ch);
解决方案 »
- 关于select下拉框 编辑信息时自动选中的问题 (smarty模板中)
- php-fpm不工作
- 为什么不能获取网卡地址GetMacAddr
- $result=$mycon->Query($querystr);查询错误
- 求大师帮类化个语句。。。谢谢。
- 如何实现在一个php页面上点击按钮跳转到另外一个php页面时带上文本框的内容做参数
- 最近想写一坛子,看了一下PHPWIND,PHPBB,DISCUZ,晕,这么难!希望另外朋友给推荐一下小一点的论坛源代码,关键是想学习它的机制,比如SEE
- apche+php下怎么禁止用户直接输入地址浏览图片
- 这个图片下载的程序怎么做?
- 多次explode切割并组合,应该怎么做呢
- Google Translate API 收费了,仅有的积分求php的其它在线翻译写法
- php建站模板
这是它们唯一的区别,超时是网络因素我觉得,和代码无关
另外你的TIMEOUT调的的确有点小了,超时就像家常便饭
都是本地的请求,而且被请求的页面只是print_r($_SERVER);如果数据是array的话,一点问题也没有,改为string则必超;时间设为30s都会超时。
另外,如果不显示的设置为POST请求(删掉curl_setopt($ch, CURLOPT_POST, true);语句),可以成功发送,但请求类型会变为GET;array的话则正常,为POST请求。
$data_string = "ispost=ok&msg=post";
$data = array("ispost"=>"ok","msg"=>"post");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://localhost/my/www/getdata.php");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
getdata.php里面print_r($_REQUEST);
谢谢各位!