zoukankan      html  css  js  c++  java
  • curl

    /**
    * curl提交数据
    * @param $url 服务访问地址
    * @param $data 提交数据 array()
    * @param $httpHeader 设置host主机头
    * @param string $method
    * @return mixed
    */
    function invoke_curl($url, $data, $method = 'POST', $httpHeader = array(), $timeout = 300)
    {
    $ch = curl_init();
    $timeout = $timeout <= 0 ? 300 : $timeout;
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);

    if(strtoupper($method) == 'POST') {
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    } else {//GET
    curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query($data));
    }
    //$httpHeader = array('Host:127.0.0.1');
    if(!empty($httpHeader) && is_array($httpHeader)) {
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
    }
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $handles = curl_exec($ch);
    //$error = curl_error($ch);//排除错误
    curl_close($ch);
    return $handles;
    }

  • 相关阅读:
    8-6实战蒙版
    8-5渐变及半透明蒙版
    8-4修改蒙版
    8-3建立蒙版
    imageNamed、imageWithContentsOfFile、imageWithData
    #import、#include、@class、@protocol、@interface
    JSON解析
    控制器的生命周期
    纯代码方式实现九宫格布局
    KVC笔记
  • 原文地址:https://www.cnblogs.com/nowphp/p/6526356.html
Copyright © 2011-2022 走看看