■ get 함수에서 headers 인자를 사용해 커스텀 헤더를 전달하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import httpx def printResponse(title, response): print(title ) print(f" response : {response}" ) print(f" response.url : {response.url}" ) print(f" response.headers['content-type'] : {response.headers['content-type']}") print(f" response.encoding : {response.encoding}" ) print(f" response.status_code : {response.status_code}" ) #print(f" response.text : {response.text}" ) print() headerDictionary = { "user-agent" : "my-app/0.0.1", "accept" : "application/json", "content-type" : "text/html; charset=utf-8" } response = httpx.get("https://httpbin.org/headers", headers = headerDictionary) printResponse("사용자 정의 헤더 전달", response) import httpx def printResponse(title, response): print(title ) print(f" response : {response}" ) print(f" response.url : {response.url}" ) print(f" response.headers['content-type'] : {response.headers['content-type']}") print(f" response.encoding : {response.encoding}" ) print(f" response.status_code : {response.status_code}" ) #print(f" response.text : {response.text}" ) print() headerDictionary = { "user-agent" : "my-app/0.0.1", "accept" : "application/json", "content-type" : "text/html; charset=utf-8" } response = httpx.get("https://httpbin.org/headers", headers = headerDictionary) printResponse("사용자 정의 헤더 전달", response) """ 사용자 정의 헤더 전달 response : <Response [200 OK]> response.url : https://httpbin.org/headers response.headers['content-type'] : application/json response.encoding : utf_8 response.status_code : 200 """ |