python -v
3.7.2
httpget.py
#!/usr/bin/env python3
# _*_ coding="utf-8" _*_
#######
# author : xy
# data : 2001/01/01
# despcription : desc
######
import http.client
server = "127.0.0.1"
port = 8080
_timeout = 10
client = http.client.HTTPConnection(server, port, timeout = _timeout)
if __name__ == "__main__":
client.request('GET', '/rest/test/t1')
res = client.getresponse()
print(res.status)
print(res.read())
httppost.py
#!/usr/bin/env python3
# _*_ coding="utf-8" _*_
#######
# author : xy
# data : 2001/01/01
# despcription : desc
# 参考: https://www.cnblogs.com/mingerlcm/p/11369444.html
# https://blog.csdn.net/joye123/article/details/93983121
######
import http.client
import json
server = "127.0.0.1"
port = 8080
_timeout = 10
client = http.client.HTTPConnection(server, port, timeout = _timeout)
p = {
'kw' : '苹果',
}
headers = {'Accept-Charset': 'utf-8', 'Content-Type': 'application/json'}
params = json.dumps(p)
params = bytes(params, 'utf8')
if __name__ == "__main__":
client.request('POST', '/rest/test/t2', headers = headers, data=params)
res = client.getresponse()
print(res.status)
print(res.read())
网友评论