PHP類比post,get

來源:互聯網
上載者:User
post調用$URL = 'http://xx/xx/xx/'; //需要提交到的頁面//下面這段是要提交的資料$post_data['email'] = $_POST['email'];$post_data['password'] = $_POST['password'];echo get_postData($URL,$post_data);

get調用$URL = 'http://xx/xx/xx/?token='.$token; //需要提交到的頁面echo get_getData($URL);

function get_getData($URL){$ch = curl_init($URL) ;curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ;curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ;$output = curl_exec($ch) ;fclose($fch) ;return $output;}

function get_postData($URL,$post_data){$referrer="";$URL_Info=parse_url($URL);if($referrer==""){    $referrer=$_SERVER["SCRIPT_URI"];}foreach ($post_data as $key=>$value){    $values[]="$key=".urlencode($value);}$data_string=implode("&",$values);if (!isset($URL_Info["port"])) {$URL_Info["port"]=80;$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";$request.="Host: ".$URL_Info["host"]."\n";$request.="Referer: $referrer\n";$request.="Content-type: application/x-www-form-urlencoded\n";$request.="Content-length: ".strlen($data_string)."\n";$request.="Connection: close\n";$request.="\n";$request.=$data_string."\n";}$fp = fsockopen($URL_Info["host"], $URL_Info["port"]);fputs($fp, $request);$i = 0;while(!feof($fp)) {$result = fgets($fp, 1024);$length = strlen($result);$s1 = substr($result, 0, 1);$s2 = substr($result, $length - 3, 1);if($s1 == '{' && $s2 == '}')$resultover = $result;}fclose($fp);return $resultover;}       

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.