zoukankan      html  css  js  c++  java
  • php中的curl

    /**
    * 请求接口返回内容
    * @param string $url [请求的URL地址]
    * @param string $params [请求的参数]
    * @param int $ipost [是否采用POST形式]
    * @return string

    * $params = array(

    *    "key" => $appkey

     *    "page" => ""

    *  );

    *  函数params参数的格式为URL-encode的请求字符串 类似、foo=bar&baz=boom

    *  $paramstring = http_build_query($params);

    *

    */
    function curl($url,$params='',$ispost=false){
    $httpInfo = array();
    $ch = curl_init();

    curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
    curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
    curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    if( $ispost )
    {
    curl_setopt( $ch , CURLOPT_POST , true );
    curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
    curl_setopt( $ch , CURLOPT_URL , $url );
    }
    else
    {
    if($params){
    curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
    }else{
    curl_setopt( $ch , CURLOPT_URL , $url);
    }
    }
    $response = curl_exec( $ch );
    if ($response === FALSE) {
    //echo "cURL Error: " . curl_error($ch);
    return false;
    }
    $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
    $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
    curl_close( $ch );
    return $response;
    }

  • 相关阅读:
    document.getElementById的简便方式
    uri编解码
    javascript数组
    前端网站收藏
    html5 canvas
    interview material
    Merge into(oracle)
    机器学习入门二 ----- 机器学习术语表
    机器学习入门一 ------- 什么是机器学习,机器学习的在实际中的用处
    Dubbo 源码分析系列之一环境搭建
  • 原文地址:https://www.cnblogs.com/web21/p/6019202.html
Copyright © 2011-2022 走看看