■ get 함수의 cookies 인자를 사용해 HTTP 호출시 쿠키 값을 전달하는 방법을 보여준다.
▶ 예제 코드 (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 |
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() cookieDictionary = {"cookie1" : "value1"} response = httpx.get('https://httpbin.org/cookies', cookies = cookieDictionary) printResponse("HTTP 호출시 쿠키 값 전달하기", response) print(f" response.json() : {response.json()}") """ HTTP 호출시 쿠키 값 전달하기 response : <Response [200 OK]> response.url : https://httpbin.org/cookies response.headers['content-type'] : application/json response.encoding : ascii response.status_code : 200 response.json() : {'cookies': {'cookie1': 'value1'}} """ |