當前位置:首頁 » 編程語言 » php發送http請求

php發送http請求

發布時間: 2023-06-05 01:51:24

⑴ 求助php如何POST提交數據

用PHP向伺服器發送HTTP的POST請求,代碼如下:

<?php
/**
*發送post請求
*@paramstring$url請求地址
*@paramarray$post_datapost鍵值對數據
*@returnstring
*/
functionsend_post($url,$post_data){
$postdata=http_build_query($post_data);
$options=array(
'http'=>array(
'method'=>'POST',
'header'=>'Content-type:application/x-www-form-urlencoded',
'content'=>$postdata,
'timeout'=>15*60//超時時間(單位:s)
)
);
$context=stream_context_create($options);
$result=file_get_contents($url,false,$context);
return$result;
}

使用的時候直接調用上面定義的send_post方法:

$post_data=array(
'username'=>'username',
'password'=>'password'
);
send_post('網址',$post_data);

⑵ php怎麼響應客戶端發送http請求

http請求有get,post。
php發送http請求有三種方式[我所知道的有三種,有其他的告訴我]。
1. file_get_contents();詳情見:http://www.jb51.net/article/41833.htm
2. curl發送請求。
3. fsocket發送。
下面說使用curl發送。
首先環境需要配置好curl組件。
在windows中讓php支持curl比較簡單:
在php.ini中將extension=php_curl.dll前面的分號去掉,
有人說需要將php根目錄的libeay32.dll和ssleay32.dll需要拷貝到系統目錄下去。我實驗不拷貝也可以。
linux中,如果使用源碼安裝,需要在make 之前,./configure --with-curl=path,
其中,path是你的 libcurl庫的位置,比如你安裝libcurl庫之後,
path可能就是/usr/local/,libcurl可以是靜態庫,也可以是動態庫。
注意libcurl庫configure的時候,可以將一些不需要的功能去掉,
比如ssl , ldap等。在php configure的時候,會去檢查libcurl中某些功能是否被開啟,進而去相應地調整生成的php。

⑶ php如何通過get方法發送http請求,並且得到返回的參數

1. 可以用curl函數或fsockopen() 與其他伺服器通訊。當然也可以用file_get_contents() 簡單一些但是有時候不好用。
2. 對方伺服器返回json或xml,或簡單的字元串
具體使用自己學習一下吧。

⑷ PHP 模擬HTTP發送POST請求

用php模擬登陸主要分為三部分1. post數據。2.根據返回的http頭,從中截出cookie段。3.偽造http頭發送請求。 我這里以用php抓取163相冊的需要密碼才能訪問的目錄為例。<?phpfunction posttohost($url, $data) //post數據if (!isset($url['query'])) $encoded = "";foreach ($data as $k=>$v) $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80);if (!$fp) return "Failed to open socket to $url[host]";fputs($fp, sprintf("POST %s%s%s HTTP/1.0\n", $url['path'], $url['query'] ? "?" : "", $url['query']));fputs($fp, "Host: $url[host]\n");fputs($fp, "Content-type: application/x-www-form-urlencoded\n");fputs($fp, "Content-length: " . strlen($encoded) . "\n");fputs($fp, "Connection: close\n\n");fputs($fp, "$encoded\n");$line = fgets($fp,1024);if (!eregi("^HTTP/1\.. 200", $line)) return;$results = ""; $inheader = 1;while(!feof($fp)) elseif ($inheader) }fclose($fp);return $results;} 答案補充 function getjs($juser,$jaid,$jcookie) //偽造http頭 答案補充 else fclose( $socket ); return $ret;}}$iurl=' http://photo.163.com/photos/'.$iuser.'/'.$aid.'/';$idata=array ('pass'=>$pass,'checking'=>'1'); //通過winsock抓包發現,輸入訪問密碼,會向163相冊發送 pass=密碼&checking=1$mystr=posttohost($iurl,$idata);$pattern='/HALFORDER=(.*?);/';preg_match($pattern,$mystr,$out);$str=getjs($iuser,$aid,$out[1]);echo $str;?>

⑸ 怎麼用PHP發送HTTP請求

var_loader:URLloader;
_loader=newURLLoader();
//建立事件的偵聽

configureListeners(_loader);
//建立urlloader的數據

varloaderData:URLVariables=newURLVariables();
loaderData.userName="kidliu";
loaderData.passWord="123456";
//建立請求地址

varurl:String="localhost/login.php";

varrequest:URLRequest=newURLRequest(url);

//把數據和請求邦定

request.data=loaderData;
//設定請求的方式

request.method=URLRequestMethod.POST;

try{

_loader.load(request);

}catch(error:Error){

trace(error);

}
(dispatcher:IEventDispatcher):void{

//載入完成事件;

dispatcher.addEventListener(Event.COMPLETE,loaderHandler);

//開始訪問事件;

dispatcher.addEventListener(Event.OPEN,loaderHandler);

//載入進度事件;

dispatcher.addEventListener(ProgressEvent.PROGRESS,loaderHandler);

//跨域訪問安全策略事件;

dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR,loaderHandler);

//Http狀態事件;

dispatcher.addEventListener(HTTPStatusEvent.HTTP_STATUS,loaderHandler);

//訪問出錯事件;

dispatcher.addEventListener(IOErrorEvent.IO_ERROR,loaderHandler);

}
privatefunctionloaderHandler(event:*):void

{

switch(event.type){

caseEvent.COMPLETE:

trace("成功:"+_loader.data);

break;

caseEvent.OPEN:

trace("open:"+event);

break;

caseProgressEvent.PROGRESS:

trace("progress:"+event);

break;

caseSecurityErrorEvent.SECURITY_ERROR:

trace("securityError:"+event);

熱點內容
郵件伺服器是什麼語言寫的 發布:2023-10-01 19:57:41 瀏覽:343
note3簡訊加密 發布:2023-10-01 19:15:26 瀏覽:111
演算法中向量 發布:2023-10-01 19:11:38 瀏覽:520
lp地址轉換工作的是什麼伺服器 發布:2023-10-01 19:03:33 瀏覽:940
機器人都有哪些配置 發布:2023-10-01 19:03:28 瀏覽:219
linux圖形界面網路 發布:2023-10-01 19:00:04 瀏覽:237
android清除緩存代碼 發布:2023-10-01 19:00:00 瀏覽:383
觸發器sql游標 發布:2023-10-01 18:59:53 瀏覽:561
java核心技術卷1基礎知識 發布:2023-10-01 18:59:16 瀏覽:247
win10ftp更改默認路徑 發布:2023-10-01 18:17:21 瀏覽:779