php調(diào)用api接口教程 PHP如何調(diào)用API接口?
PHP如何調(diào)用API接口?它可以通過(guò)用PHP模擬post請(qǐng)求來(lái)調(diào)用。PHP模擬post提交方法:通過(guò)curl函數(shù)PHP代碼:$post數(shù)據(jù)=數(shù)組()$post數(shù)據(jù)[“clientname”]=“tes
PHP如何調(diào)用API接口?
它可以通過(guò)用PHP模擬post請(qǐng)求來(lái)調(diào)用。
PHP模擬post提交方法:
通過(guò)curl函數(shù)
PHP代碼:
$post數(shù)據(jù)=數(shù)組()
$post數(shù)據(jù)[“clientname”]=“test08”
$post數(shù)據(jù)[“clientpasswd”]=“test08”
$post數(shù)據(jù)[“submit”]=“submit”http://xxx.xxx.xxx.xx/xx/xxx/top.php“
$o=”“
foreach($post數(shù)據(jù)為”$k=>$v)
{
$o.=“$k=”.urlencode($v)?!?amp”
}
$postuuDATA=substr($o,0,-1)
$ch=curluInit()
curluSetOpt($ch,CURLOPTuPost,1)
curluSetOpt($ch,CURLOPTuHeader,0)
curluOpt($ch,CURLOPTuURL,$URL)
//支持cookie
curluOpt($ch,CURLOPTuCookieJar,” cookie.txt文件“)
curluuopt setopt($ch,CURLOPTuupostfields,$postudata)
$result=curluexec($ch)