■ post 함수의 json 인자를 사용해 JSON 데이터를 전달하는 방법을 보여준다.
▶ 예제 코드 (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() jsonDictionary = { "value1" : 123, "value2" : True, "value3" : ["a", "b", "c"] } response = httpx.post("https://httpbin.org/post", json = jsonDictionary) printResponse("JSON 데이터 전달", response) """ JSON 데이터 전달 response : <Response [200 OK]> response.url : https://httpbin.org/post response.headers['content-type'] : application/json response.encoding : ascii response.status_code : 200 """ |