투케이2K

64. (python/파이썬) [Mac Os] : [requests] : HTTP 통신 모듈 사용해 Post QueryString 요청 및 Response 응답 확인 본문

Python

64. (python/파이썬) [Mac Os] : [requests] : HTTP 통신 모듈 사용해 Post QueryString 요청 및 Response 응답 확인

투케이2K 2024. 5. 4. 09:01
반응형

[개발 환경 설정]

개발 툴 : VsCode

개발 언어 : python

 

[소스 코드]

# --------------------------------------------------------------
# [import]
# --------------------------------------------------------------
import requests
# --------------------------------------------------------------



# --------------------------------------------------------------
# [요약 설명]
# --------------------------------------------------------------
# 1. import requests : 파이썬에서 HTTP Request 요청을 할 때 사용합니다
# --------------------------------------------------------------
# 2. 모듈 설치 방법 참고 사이트 : https://blog.naver.com/kkh0977/223435974300
# --------------------------------------------------------------



# --------------------------------------------------------------
# [class start]
# --------------------------------------------------------------



# --------------------------------------------------------------
# [main start]
# --------------------------------------------------------------


# [HTTP 통신 URL 주소 지정]
url = 'https://jsonplaceholder.typicode.com/posts?userId=1&id=1'


# [HTTP 요청 헤더 headers 정의]
headers = {
	'Content-Type': 'application/json'
}


# [HTTP 요청 타임 아웃 시간 정의]
timeOut = 30


# [HTTP 요청 수행 및 응답 데이터 확인]
response = requests.post(url, headers=headers, timeout=timeOut)

statusCode = response.status_code
responseData = response.text


# [로그 출력]
print("")
print("----------------------------------------")
print("url :: ", url)
print("----------------------------------------")
print("headers :: ", headers)
print("----------------------------------------")
print("statusCode :: ", statusCode)
print("----------------------------------------")
print("responseData :: ", responseData)
print("----------------------------------------")
print("")


# --------------------------------------------------------------
# [main end]
# --------------------------------------------------------------



# --------------------------------------------------------------
# [class end]
# --------------------------------------------------------------
 

[결과 출력]

 

 

반응형
Comments