首頁  >  文章  >  後端開發  >  php怎麼存取介面

php怎麼存取介面

(*-*)浩
(*-*)浩原創
2019-10-17 10:14:203822瀏覽

透過php模擬post請求即可呼叫。

php怎麼存取介面

php 模擬POST提交的方法:

為了使用PHP的cURL函數,你需要安裝libcurl套件。  (建議學習:PHP影片教學

libcurl目前支援http、https、ftp、gopher、telnet、dict、file和ldap協定。 libcurl同時也支援HTTPS認證、HTTP POST、HTTP PUT、 FTP 上傳(這個也能透過PHP的FTP擴充完成)、HTTP 基於表單的上傳、代理、cookies和使用者名稱 密碼的認證。

Php程式碼:

$post_data = array(); 
$post_data['clientname'] = "test08"; 
$post_data['clientpasswd'] = "test08"; 
$post_data['submit'] = "submit"; 
$url='http://xxx.xxx.xxx.xx/xx/xxx/top.php'; 
$o=""; 
foreach ($post_data as $k=>$v) 
{ 
$o.= "$k=".urlencode($v)."&"; 
} 
$post_data=substr($o,0,-1); 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_URL,$url); 
//为了支持cookie 
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
$result = curl_exec($ch);

以上是php怎麼存取介面的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn