mlsb.net
当前位置:首页 >> python发送post请求 >>

python发送post请求

import urllib2import urllib#定义一个要提交的数据数组(字典)data = {}data['username'] = 'zgx030030'data['password'] = '123456'#定义post的地址url = 'http://www.test.com/post/'post_data = urllib.urlencode(data)#提交,发送数据req = ...

import httplib, urllibfrom urlparse import urlparsedef httppost(url, **kwgs): httpClient = None conn = urlparse(url) try: params = urllib.urlencode(dict(kwgs)) header = {"Content-type": "application/x-www-form-urlencoded", "Acc...

from urllib import request request.urlopen() def post(url, data=None, headers=None, timeout=2, decode='utf-8'): rt = HttpReturn() if headers is None: headers = {} post_data = urllib.parse.urlencode(data).encode(decode) try: req...

可以参考如下三种方法: 一、application/x-www-form-urlencoded import urlliburl = "http://www.example.com"body_value = {"package": "com.tencent.lian","version_code": "66" }body_value = urllib.urlencode(body_value)request = urllib...

head = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36', ...

我使用的的python3.5,代码如下: from urllib.parse import urlencodefrom urllib.request import urlopendef send_to_server(url, post_data = None): if post_data: para = urlencode(post_data) page = urlopen(url, para.encode('utf-8')) #...

使用requests库就可以了: pip install requests payload = {'key1': 'value1', 'key2': 'value2'} r = requests.post("http://httpbin.org/post", data=payload) print(r.text) 然后参考这个网址: http://docs.python-requests.org/en/latest/...

import urllib,urllib2url="http://exmaple.com"data={'usename':'username', 'pass':'pass'}para=urllib.urlencode(data)resposne=urllib2.urlopen(url,para)

使用requests库就可以了: pip install requests payload = {'key1': 'value1', 'key2': 'value2'} r = requests.post("ht tp:/ /httpbin.or g/post", data=payload) print(r.text) 然后参考这个网址: htt p:/ /docs.python-reques ts.org /en/...

import urllib2 import urllib #定义一个要提交的数据数组(字典) data = {} data['username'] = 'zgx030030' data['password'] = '123456' #定义post的地址 url = '' post_data = urllib.urlencode(data) #提交,发送数据 req = urllib2.urlopen...

网站首页 | 网站地图
All rights reserved Powered by www.mlsb.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com