■ Cookies 함수를 사용해 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 33 34 35 |
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() cookies = httpx.Cookies() cookies.set("cookie_on_domain" , "hello, there!", domain = "httpbin.org") cookies.set("cookie_off_domain", "nope" , domain = "example.org") response = httpx.get('http://httpbin.org/cookies', cookies = cookies) printResponse("HTTP 호출시 Cookies 객체를 쿠키 값으로 전달하기", response) print(f" response.json() : {response.json()}") """ HTTP 호출시 Cookies 객체를 쿠키 값으로 전달하기 response : <Response [200 OK]> response.url : http://httpbin.org/cookies response.headers['content-type'] : application/json response.encoding : ascii response.status_code : 200 response.json() : {'cookies': {'cookie_on_domain': 'hello, there!'}} """ |