使用curl post数据问题
最近遇到一个很奇怪的问题
在发送post请求时,如果POSTFIELDS的类型为string的话,就会超时,但类型为array就没问题。
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$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);
$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;<div class="clear"> </div>