共計 508 個字符,預計需要花費 2 分鐘才能閱讀完成。
在 PHP 中,你可以使用 file_get_contents()
函數來發送 GET 請求,并設置請求頭。以下是一個示例代碼:
<?php
// 創建請求頭數組
$options = array('http' => array('header' => "Content-Type: application/x-www-form-urlencoded\r\n"
)
);
// 創建請求上下文
$context = stream_context_create($options);
// 發送 GET 請求
$response = file_get_contents('http://example.com/api', false, $context);
// 輸出響應內容
echo $response;
?>
在上述示例代碼中,我們首先創建了一個包含 Content-Type
請求頭的關聯數組 $options
。然后使用stream_context_create()
函數將該數組轉換為請求上下文。最后,通過調用 file_get_contents()
函數發送 GET 請求,并傳遞請求上下文作為第三個參數。
丸趣 TV 網 – 提供最優質的資源集合!
正文完