Tech Blog of Pinomaker
#모듈 추출
import requests, json

#URL 설정
url = "http://localhost:8080/..."

#보낼 데이터를 json.dumps()를 이용하여 json으로 변환
body = json.dumps({
    "id" : 3,
    "name" : "감자",
    "weight" : 320
})

#header 설정으로, json 통신 셋팅
header = {
    "Content-Type" : "application/json"
}

#.content를 이용한 요청 후 응답을 res에 저장
res = requests.post(url, body, headers=header ).content

#응답 출력
print(res)

'Language > Python' 카테고리의 다른 글

[Python] 리스트(2)  (0) 2022.06.06
[Python] 리스트(1)  (0) 2022.06.06
[Python] 튜플  (0) 2022.05.30
[Django] Django 개발 환경 구축(Mac, Anaconda, IntelliJ)  (0) 2022.05.07
[Python] 내장 함수  (0) 2022.04.27
profile

Tech Blog of Pinomaker

@pinomaker

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!