利用PHP fsockopen 模擬POST/GET傳送數(shù)據(jù)的方法
使用php可以模擬 post 和 get 傳送數(shù)據(jù)到別的網(wǎng)頁或站點(diǎn)
$arr=array(
'user'=>'test',
'password'=>''
);
sock_get($post_url,$arr);
sock_post($post_url,$arr);
//fsocket模擬get提交
function sock_get($url,$query=array()){
$query_str = http_build_query($query);
$<span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" target="_blank" mpid="" style="text-decoration: none;"><span style="color:#ff;font-size:px;width:auto;height:auto;float:none;">info</span></a></span> = parse_url($url);
$port = isset($info['port'])? $info['port'] : ;
$query_str = empty($info["query"])?$query_str:$info["query"].'&'.$query_str;
$fp = fsockopen($info["host"], $port, $errno, $errstr, );
if(!$fp){
return FALSE;
}
//$<span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" target="_blank" mpid="" style="text-decoration: none;"><span style="color:#ff;font-size:px;width:auto;height:auto;float:none;">head</span></a></span> = "GET ".$info['path']."?".$info["query"]." HTTP/.\r\n";
$head = "GET ".$info['path']."?".$query_str." HTTP/.\r\n";
$head .= "Host: ".$info['host']."\r\n";
$head .= "\r\n";
$write = fputs($fp,$head);
while(!feof($fp)){
$<span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" target="_blank" mpid="" style="text-decoration: none;"><span style="color:#ff;font-size:px;width:auto;height:auto;float:none;">line</span></a></span> = fread($fp,);
echo $line;
}
fclose($fp);
return true;
}
//fsockopen模擬POST
function sock_post($url,$<span id="_nwp" style="width: auto; height: auto; float: none;"><a id="_nwl" target="_blank" mpid="" style="text-decoration: none;"><span style="color:#ff;font-size:px;width:auto;height:auto;float:none;">data</span></a></span>=array()){
$query = http_build_query($data);
$info = parse_url($url);
$fp = fsockopen($info["host"], , $errno, $errstr, );
$head = "POST ".$info['path']."?".$info["query"]." HTTP/.\r\n";
$head .= "Host: ".$info['host']."\r\n";
$head .= "Referer: http://".$info['host'].$info['path']."\r\n";
$head .= "Content-type: application/x-www-form-urlencoded\r\n";
$head .= "Content-Length: ".strlen(trim($query))."\r\n";
$head .= "\r\n";
$head .= trim($query);
$write = fputs($fp, $head);
while (!feof($fp))
{
$line = fread($fp,);
echo $line;
}
}
以上內(nèi)容是給大家分享的利用PHP fsockopen 模擬POST/GET傳送數(shù)據(jù)的方法,希望大家能夠喜歡,更多有關(guān)php fsockopen知識(shí)請(qǐng)持續(xù)關(guān)注本站,謝謝。
- PHP基于curl模擬post提交json數(shù)據(jù)示例
- php使用CURL模擬GET與POST向微信接口提交及獲取數(shù)據(jù)的方法
- PHP socket 模擬POST 請(qǐng)求實(shí)例代碼
- php模擬post上傳圖片實(shí)現(xiàn)代碼
- PHP模擬post提交數(shù)據(jù)方法匯總
- php實(shí)現(xiàn)模擬post請(qǐng)求用法實(shí)例
- php模擬post提交數(shù)據(jù)的方法
- php curl模擬post提交數(shù)據(jù)示例
- php curl模擬post請(qǐng)求小實(shí)例
- php模擬post提交請(qǐng)求調(diào)用接口示例解析
相關(guān)文章
yii2.0框架實(shí)現(xiàn)上傳excel文件后導(dǎo)入到數(shù)據(jù)庫的方法示例
這篇文章主要介紹了yii2.0框架實(shí)現(xiàn)上傳excel文件后導(dǎo)入到數(shù)據(jù)庫的方法,結(jié)合實(shí)例形式詳細(xì)分析了yii2.0上傳excel文件后導(dǎo)入到數(shù)據(jù)庫的相關(guān)模型、視圖、控制器實(shí)現(xiàn)技巧,需要的朋友可以參考下2020-04-04
Yii實(shí)現(xiàn)的多級(jí)聯(lián)動(dòng)下拉菜單
這篇文章主要介紹了Yii實(shí)現(xiàn)的多級(jí)聯(lián)動(dòng)下拉菜單,包括視圖、模型及控制器的相關(guān)實(shí)現(xiàn)代碼,涉及基于Yii的數(shù)據(jù)庫查詢、數(shù)組遍歷與數(shù)據(jù)顯示等相關(guān)操作技巧,需要的朋友可以參考下2016-07-07
一次因composer錯(cuò)誤使用引發(fā)的問題與解決
這篇文章主要給大家介紹了一次因composer錯(cuò)誤使用引發(fā)的問題與解決方法,文中通過示例代碼以及圖文介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03
tp5.1 框架數(shù)據(jù)庫-數(shù)據(jù)集操作實(shí)例分析
這篇文章主要介紹了tp5.1 框架數(shù)據(jù)庫-數(shù)據(jù)集操作,結(jié)合實(shí)例形式分析了tp5.1 框架數(shù)據(jù)庫查詢結(jié)果數(shù)據(jù)集獲取、遍歷相關(guān)操作技巧與使用注意事項(xiàng),需要的朋友可以參考下2020-05-05
PHP的new static和new self的區(qū)別與使用
這篇文章主要介紹了PHP的new static和new self的區(qū)別與使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
PHP調(diào)用API接口實(shí)現(xiàn)天氣查詢功能的示例
下面小編就為大家?guī)硪黄狿HP調(diào)用API接口實(shí)現(xiàn)天氣查詢功能的示例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-09-09

