亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長(zhǎng)資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    如何通過(guò)file_get_contents()發(fā)送GET、POST請(qǐng)求?(方法介紹)

    如何通過(guò)file_get_contents()發(fā)送GET、POST請(qǐng)求?(方法介紹)

    服務(wù)器端執(zhí)行HTTP請(qǐng)求,大家經(jīng)常使用的就是CURL,curl工具的確是很好的數(shù)據(jù)文件傳輸工具,那么除此之外還有其他的工具能實(shí)現(xiàn)這個(gè)功能嗎?

    現(xiàn)在為你介紹一個(gè)很常見(jiàn)的工具 file_get_content()

    納尼,這不是PHP文件操作函數(shù)嗎??? 竟然還能實(shí)現(xiàn)GET POST 請(qǐng)求???

    這里可以很明確的告訴你,完全可以?。?!

    廢話不多說(shuō),直接上代碼。有問(wèn)題來(lái)打我、記得帶醫(yī)藥費(fèi)

    1、【GET請(qǐng)求】

    $data = array( 'name'=>'zhezhao','age'=>'23'); $query = http_build_query($data);  $url = 'http://localhost/get.php';//這里一定要寫(xiě)完整的服務(wù)頁(yè)面地址,否則php程序不會(huì)運(yùn)行  $result = file_get_contents($url.'?'.$query);

    2、【POST請(qǐng)求】

    $data = array('user'=>'jiaxiaozi','passwd'=>'123456'); $requestBody = http_build_query($data); $context = stream_context_create(['http' => ['method' => 'POST', 'header' => "Content-Type: application/x-www-form-urlencodedrn"."Content-Length: " . mb_strlen($requestBody), 'content' => $requestBody]]); $response = file_get_contents('http://server.test.net/login', false, $context);

    相關(guān)教程推薦:《PHP教程》

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)