[Python] http request(http.client)

반응형
반응형

 

▶ GET

#!/bin/usr/python

import http.client

conn = http.client.HTTPConnection("httpbin.org")

conn.request("GET", "/get")
res = conn.getresponse()

print(res.status, res.reason)

conn.close()

 

▶ PUT

#!/usr/bin/python

import http.client

conn = http.client.HTTPConnection("httpbin.org")

datas = {'data1': 1, 'data2': 2, 'data3': 3}
headers = {"Content-type":"application/json"}
conn.request("POST", "/post", str(datas), headers)

res = conn.getresponse()

print(res.status, res.reason)

conn.close()

 

▶ 출력

200 OK

 

반응형

댓글

Designed by JB FACTORY

loading