用PHP向服務(wù)器發(fā)送HTTP的POST請(qǐng)求,代碼如下:

慈利網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。成都創(chuàng)新互聯(lián)于2013年開始到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)。
?php
/**????
*?發(fā)送post請(qǐng)求????
*?@param?string?$url?請(qǐng)求地址????
*?@param?array?$post_data?post鍵值對(duì)數(shù)據(jù)????
*?@return?string????
*/????
function?send_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?//?超時(shí)時(shí)間(單位:s)????
)????
);????
$context?=?stream_context_create($options);????
$result?=?file_get_contents($url,?false,?$context);?????????????
return?$result;????
}
使用的時(shí)候直接調(diào)用上面定義的send_post方法:
$post_data?=?array(
'username'?=?'username',
'password'?=?'password'
);
send_post('網(wǎng)址',?$post_data);
看代碼應(yīng)該是test2去獲取test1的數(shù)據(jù),getData.php里,加上對(duì)應(yīng)的接口文件名應(yīng)該就好了
B service :
//getData.php
$url?=?'';
$ch?=?curl_init();
curl_setopt($ch,?CURLOPT_URL,?$url);
curl_setopt($ch,?CURLOPT_HEADER,?true);
$result?=?curl_exec($ch);
echo?$result;
有很多種方式,其實(shí)就像在客戶端向服務(wù)器發(fā)送請(qǐng)求一個(gè)意思...
網(wǎng)頁名稱:php跨服務(wù)器請(qǐng)求數(shù)據(jù) php接口跨域問題
網(wǎng)站URL:http://chinadenli.net/article8/ddoddop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、移動(dòng)網(wǎng)站建設(shè)、軟件開發(fā)、、標(biāo)簽優(yōu)化、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)