zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    华为"128为大整数相加"机试题
    ORA-12545: 因目标主机或对象不存在, 连接失败
    VS2010 安装使用STLPort
    Debian 入门安装与配置1
    CF1072A Palindromic Twist 思维
    解决让刷新页面时不提示 "重试或取消”对话框
    php优化及高效提速问题小结
    让Tomcat支持php
    Php邮件发送源码
    使用iconv提示未知错误
  • 原文地址:https://www.cnblogs.com/xingmeng/p/3468877.html
Copyright © 2011-2022 走看看