# -*- coding: utf-8 -*-
from urllib.parse import urlencode
try:
import httplib2
except ImportError:
print('错误:')
print(' httplib2这个库没有找到,程序无法继续执行!')
exit(255)
def network_post_proc(self, use_cache = True):
'''POST动作'''
post_request_str = 'http://192.168.0.54/softlist' # 请求URL
# print('->%s' % post_request_str)
if use_cache:
h = httplib2.Http('.cache')
else:
h = httplib2.Http('no‐cache')
params = {
'uid' : 'bsgqaz',
'hid' : 'VB6a2a6681-7fff12db',
'mac' : '08-00-20-8c-90-5f-ef'
}
headers = {'Content-type' : 'application/x-www-form-urlencoded', 'Accept' : 'text/plain'}
response, content = h.request(post_request_str, 'POST', urlencode(params), headers)
post_ret = False
if response.status == 200:
post_ret = True
print(content.decode('utf-8'))
else:
post_ret = False
return post_ret
# 应用程序入口
if __name__ == '__main__':
post_ret = network_post_proc(False)
Python发一个POST请求
最新推荐文章于 2024-09-22 11:51:43 发布