在Python中,您可以使用requests
庫來發送帶有自定義請求頭的HTTP請求
pip install requests
然后,您可以使用以下代碼示例發送帶有自定義請求頭的GET請求:
import requests
url = "https://api.example.com/data"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
"Authorization": "Bearer your_access_token",
"Accept": "application/json"
}
response = requests.get(url, headers=headers)
print(response.text)
在這個例子中,我們設置了三個自定義請求頭:User-Agent
,Authorization
和Accept
。您可以根據需要修改這些值。