第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

php curl 發(fā)送get或者post請求

標(biāo)簽:
PHP

php可以扮演资料的发送者。

  1. 简单的get


$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "http://SomeDomain/SamplePath?SomeVar=test");curl_exec($ch);curl_close($ch);


2.  简单的post


$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "http://SomeDomain/SamplePath");curl_setopt($ch, CURLOPT_POST, true); // 啟用POSTcurl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query( array"a"=>"123""b"=>"321") )); curl_exec($ch); curl_close($ch);


3. 高级的post,可设置多个参数


$toURL "http://SomeDomain/SamplePath?SomeVar=XX";$post array(  "a"=>"123",  "b"=>"321",);$ch = curl_init();$options array(  CURLOPT_URL=>$toURL,  CURLOPT_HEADER=>0,  CURLOPT_VERBOSE=>0,  CURLOPT_RETURNTRANSFER=>true,  CURLOPT_USERAGENT=>"Mozilla/4.0 (compatible;)",  CURLOPT_POST=>true,  CURLOPT_POSTFIELDS=>http_build_query($post),);curl_setopt_array($ch$options);// CURLOPT_RETURNTRANSFER=true 会返回服务器响应代码,// false 时只返回成功与否;$result = curl_exec($ch); curl_close($ch);echo $result;


4. post 发送文件


发送端代码:


$target_url 'http://127.0.0.1/accept.php';        //This needs to be the full path to the file you want to send.    $file_name_with_full_path realpath('./sample.jpeg');        /* curl will accept an array here too.         * Many examples I found showed a url-encoded string instead.         * Take note that the 'key' in the array will be the key that shows up in the         * $_FILES array of the accept script. and the at sign '@' is required before the         * file name.         */    $post array('extra_info' => '123456','file_contents'=>'@'.$file_name_with_full_path);             $ch = curl_init();    curl_setopt($ch, CURLOPT_URL,$target_url);    curl_setopt($ch, CURLOPT_POST,1);    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);    $result=curl_exec ($ch);    curl_close ($ch);    echo $result


接收端代码:


$uploaddir realpath('./') . '/';$uploadfile $uploaddir basename($_FILES['file_contents']['name']);echo '<pre>';    if (move_uploaded_file($_FILES['file_contents']['tmp_name'], $uploadfile)) {        echo "File is valid, and was successfully uploaded.\n";    else {        echo "Possible file upload attack!\n";    }    echo 'Here is some more debugging info:';    print_r($_FILES);    echo "\n<hr />\n";    print_r($_POST);print "</pr" "e>\n";


點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學(xué)

大額優(yōu)惠券免費領(lǐng)

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消