我正在嘗試創建一個 cURL api,假設下面是我的 curl 請求代碼,其中 http://localhost/api/endpoint.php 是我的端點。在 endpoint.php 檔案中,代碼方面實際上會發生什么?如何CURLOPT_USERPWD在 endpoint.php 頁面中實際獲取通過 cURL 請求發送的資料,例如資料?謝謝。
$ch = curl_init();
$url = 'http://localhost/api/endpoint.php';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERPWD, 'alex:password123');
$headers = array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
'Accept-Language: en_US'
);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$vars['grant_type'] = 'client_credentials';
$req = http_build_query($vars);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
$response = curl_exec($ch);
uj5u.com熱心網友回復:
您可以通過$_SERVERsuperglobal訪問這些資料。
端點:
<?php
$user = $_SERVER['PHP_AUTH_USER']; // alex
$password = $_SERVER['PHP_AUTH_PW']; // password123
uj5u.com熱心網友回復:
在您的檔案 endpoint.php 中,您可以使用
print_r($_POST);
在你的卷曲列印回應之后
print_r($response);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/417927.html
標籤:
上一篇:包羅萬象的HTML編碼物體
