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 = ...

使用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/...

python发送post和get请求get请求:使用get方式时,请求数据直接放在url中。方法一、import urllibimport urllib2url = "http://192.168.81.16/cgi-bin/python_test/test.py?ServiceCode=aaaa"req = urllib2.Request(url)print reqres_data = url...

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...

import requests s = requests.session()login_data = {'email': '***', 'password': '***', }# post 数据s.post('http://www.zhihu.com/login', login_data) # 验证是否登陆成功,抓取'知乎'首页看看内容r = s.get('http://www.zhihu.com')

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...

你运气真好,我这刚好有现成的,下面大写的常量就是一些字符串,涉及我们自己的协议,就不发你了,你随便写个就行 def RequestCenter( data,url,web="127.0.0.1" ,port=9228 ): headDic = {} headDic[REQUEST_HEAD_LENGTH] = len( data ) tempLi...

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

我使用的的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')) #...

可以使用python的requests库。 url = 'https://example.com'data = {'stid': '268779237', 'src': 'url'}response = requests.post(url, data)

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