国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

php - laravel獲取別人提供的api數(shù)據(jù)
大家講道理
大家講道理 2017-05-16 13:02:43
0
4
576

別人給我一個(gè)url 還有參數(shù)是json類型的數(shù)組
我要在laravel請求這個(gè)url得到數(shù)據(jù)???具體代碼該怎么實(shí)現(xiàn)

大家講道理
大家講道理

光陰似箭催人老,日月如移越少年。

全部回復(fù)(4)
世界只因有你

或者

        $url = 'http://www.baidu.com/';
        $data['param1'] = '數(shù)組參數(shù)';
        $data['param2'] = '數(shù)組參數(shù)';
        $params=json_encode($data) ;
        $result = file_get_contents($url.'?param='.$params);

---------------------------------下邊是另一種方法了---------------------------------------------

static function reqUrl($url,$params=false,$ispost=0){
        $httpInfo = array();
        $ch = curl_init();

        curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
        curl_setopt( $ch, CURLOPT_USERAGENT , 'Data' );
        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;
    }
洪濤

雷雷

黃舟

從接口獲取數(shù)據(jù)?ajax或者curl吧

某草草

curl請求接口獲取數(shù)據(jù)??梢允褂孟耮uzzlehttp/guzzle這個(gè)包,里面封裝了curl的操作。

最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板