# -*- coding: utf-8 -*-
##python 2版本
import urllib2
# http发送报文
def httpsend(url, bw):
req = urllib2.Request(url, bw)
res_data = urllib2.urlopen(req)
res = res_data.read()
print(res) # 打出响应信息
if __name__ == "__main__":
url = "http://20.0.1.157:30043/OMP"
bw = '请求报文'
httpsend(url, bw)
##python3 不需要引入包,直接使用
from urllib import request
import json
# http发送报文
def httpsend(url, bw):
textmod = json.dumps(bw).encode(encoding='utf-8')
header_dict = {'Accept': 'application/json', 'Content-Type': 'application/json'}
req = request.Request(url=url, data=textmod, headers=header_dict)
res = request.urlopen(req)
res = res.read() # 默认获取到的是16进制'bytes'类型数据 Unicode编码
res = res.decode(encoding='utf-8') # 如果如需可读输出则需decode解码成对应编码
print(res) # 打出响应信息
if __name__ == "__main__":
url = "http://test/encrypt/aes/multiple"
bw = '1111,222'
httpsend(url, bw)