1:
发送图片字节集 无参
defGSreturn_code(pic,pic_len,type):#GS答题
#1000 字母api2.jysnd.com:10680 识别端口 api6.jysnd.com:10681 取答案端口 api6.jysnd.com:10682 报错端口 1对1
rowd = requests.post('http://127.0.0.1/?a.php',data=pic)
ID = rowd.text
returnr.text
2:图片带有参数-表单格式
defDDreturn_code(pic,pic_len,type):#
tf = tempfile.NamedTemporaryFile(delete=True)
tf.write(pic)
tf.seek(0)
#m = [('image', (filename, tf))]
m = {'username':'a','password':'b'}
multiple_files = {'image':tf}
# {'image': < open file 'test.jpg', mode'rb'at 0x0000000003292300 >}
printmultiple_files
try:
url='http://127.0.0.1/k.php'
r = requests.post(url,files=multiple_files,data=m,timeout=5,headers= {'Connection':'close'})
tf.close()
printr.content
printr.encoding
returnr.text
except:#处理其它的异常
tf.close()
return'err'
第三种 图片带有参数-表单格式 直接组合数据发送
defDDreturn_code(pic,pic_len,type):
k ='''-----------------------------8d070bdf16538b4
Content-Disposition: form-data; name="username"
a
-----------------------------8d070bdf16538b4
Content-Disposition: form-data; name="password"
b
-----------------------------8d070bdf16538b4
Content-Disposition: form-data; name="image"; filename="System.Byte[]"
Content-Type: image/gif
'''
k_end ='''
-----------------------------8d070bdf16538b4--'''
m_data=k+pic+k_end
try:
url='http://127.0.0.1/k.php'
#(“Content-Type”, “multipart/form-data; boundary=---------------------------8d070bdf16538b4”)
r = requests.post(url,data=m_data,timeout=5,headers= {'Content-Type':'multipart/form-data; boundary=---------------------------8d070bdf16538b4'})
printr.content
printr.encoding
returnr.text
except:#处理其它的异常
return'err'