php中運(yùn)用http調(diào)用的GET和POST方法示例
更新時(shí)間:2014年09月29日 17:26:02 投稿:whsnow
調(diào)用的GET和POST方法,使用到的函數(shù)是curl_init, curl_setopt, curl_exec,curl_close,默認(rèn)是GET方法
使用到的函數(shù)是curl_init, curl_setopt, curl_exec,curl_close。
默認(rèn)是GET方法,可以選擇是否使用Header:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "$url"); curl_setopt($ch, CURLOPT_TIMEOUT, 2); curl_setopt($ch, CURLOPT_HEADER, 1); //如果設(shè)為0,則不使用header curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $result = curl_exec($ch); curl_close($ch);
POST方法:
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'$url');
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
$vars =sprintf('from=%d&to=%d&subject=%s&body=%s',$from, $to, urlencode($subject), urlencode($body));
curl_setopt($ch,CURLOPT_POSTFIELDS,$vars);
$ret = curl_exec($ch);
curl_close($ch);
您可能感興趣的文章:
- PHP中$GLOBALS[''HTTP_RAW_POST_DATA'']和$_POST的區(qū)別分析
- PHP中Http協(xié)議post請(qǐng)求參數(shù)
- php 利用socket發(fā)送HTTP請(qǐng)求(GET,POST)
- 使用PHP Socket 編程模擬Http post和get請(qǐng)求
- PHP實(shí)現(xiàn)支持GET,POST,Multipart/form-data的HTTP請(qǐng)求類(lèi)
- php中用socket模擬http中post或者get提交數(shù)據(jù)的示例代碼
- php獲取通過(guò)http協(xié)議post提交過(guò)來(lái)xml數(shù)據(jù)及解析xml
- PHP使用Http Post請(qǐng)求發(fā)送Json對(duì)象數(shù)據(jù)代碼解析
相關(guān)文章
php實(shí)現(xiàn)的后臺(tái)表格分頁(yè)功能示例
這篇文章主要介紹了php實(shí)現(xiàn)的后臺(tái)表格分頁(yè)功能,涉及php針對(duì)數(shù)據(jù)庫(kù)的連接、查詢(xún)、刪除、動(dòng)態(tài)生成表格等相關(guān)操作技巧,需要的朋友可以參考下2017-10-10
解決PHP程序運(yùn)行時(shí):Fatal error: Maximum execution time of 30 seconds
最近做的程序中涉及到的循環(huán)比較多且處理的情況較復(fù)雜,在運(yùn)行程序時(shí)出現(xiàn)執(zhí)行超時(shí)提示如下:Fatal error: Maximum execution time of 30 seconds exceeded in D:\php\AppServ\www\sum3\test.php on line 3通過(guò)在網(wǎng)上搜索,找到了解決方法和大家分享,下面來(lái)一起看看吧。2016-11-11

