curl要注意的几点

1.post提交数据

$postData = array(
                'paramCity' => array(array('id' => $city_id, 'day' => $city_days, 'name' => $city_name)),
                'paramAttr' => $paramAttr,
                'paramBiqu' => $must_go ? $must_go['param_value'] : 4,    //必去控制
                'paramPlayRhythm' => $rhythm ? $rhythm['param_value'] : 3,    //行程控制
                'paramBudget' => $budget ? $budget['param_value'] : 3,    //预算控制
                'paramSelectedLocation' => '',
                'paramSelectedFood' => 1,    //美食控制
                'paramNeedFood' => 1,    //美食控制
                'paramNeedBar' => 1,    //酒吧控制
                'paramDateSetting' => array('start_date' => $start_time, 'end_date' => $end_time),
                'paramCurTripId' => 3,    //首次游等种类的选择控制,
                'is_control' => 1    //是网页一步一步操作还是通过工具        1:人工控制
            );

提交的话,用http_build_query组装即可。

curl_setopt($ch, CURLOPT_POST, count($postData));//post提交方式
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
                
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $result = curl_exec($ch);
            $errorCode = curl_errno($ch);
            curl_close($ch);
            
            print_r($result);exit;
            
            if(0 !== $errorCode) {
                echo 'failed';exit;
            } else {
                echo 'success';exit;
            }

 

2.如果要继续保持本站session的调用,要加上如下的语句

1 session_start();
2 session_write_close();
3 curl_setopt($ch,CURLOPT_COOKIE,session_name().'='.session_id());    //保持继续能读取session

 

posted @ 2013-12-11 10:55  幻星宇  阅读(384)  评论(0编辑  收藏  举报