본문 바로가기
App Programming

REST API (HTTP Requests / POST) (2)

by goatlab 2022. 5. 11.
728x90
반응형
SMALL

Request

 

import requests

url='https://www.naver.com/'
r=requests.get(url)
r.status_code:200
r.request.headers

r.request.body:None

header=r.headers

header['date']
header['Content-Type']
r.encoding
r.text[0:100]

url_get='http://httpbin.org/get'
payload={"name":"Joseph","ID":"123"}
r=requests.get(url_get, params=payload)

r.url
r.request.body

r.url
r.request.body

r.json()
r.json()['args']

 

POST

 

import requests

url_get='http://httpbin.org/get'
url_post="http://httpbin.org/post"
payload={"name":"Joseph","ID":"123"}
r=requests.get(url_get, params=payload)

r_post=requests.post(url_post, data=payload)

print("POST request URL:", r_post.url)
print("GET request URL:", r.url)

r_post.json()['form']

728x90
반응형
LIST

'App Programming' 카테고리의 다른 글

Swift  (0) 2022.06.29
REST API (Webscraping) (3)  (0) 2022.05.11
REST API (1)  (0) 2022.05.11
python flask error :[Errno 48] Address already in use  (0) 2022.01.18
API  (0) 2022.01.18