mwbr.net
当前位置:首页 >> 如何用Python写一个http post请求 >>

如何用Python写一个http post请求

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

python发送post和get请求get请求:使用get方式时,请求数据直接放在url中。方法一、import urllibimport urllib2url = "

使用re模块就可以写出来了 demo如下 #coding=utf8 import requests import re headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36', } for i in r...

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

可以参考如下三种方法: 一、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...

import urllibimport httplibheaders = {"Content-type": "application/x-www-form-urlencoded; charset=UTF-8","Accept": "*/*"}params = {'username':'xxxx'} data = urllib.urlencode(params) host = '127.0.0.1'url = '/login'conn = httpli...

用这个:class urllib2.Request(url[, data][, headers][, origin_req_host][, unverifiable]) 其中data就是post的内容。 从别的地方找了个例子一看就能懂。 import urllibimport urllib2url = 'http://umbra.nascom.nasa.gov/cgi-bin/eit-catal...

测试用CGI,名字为test.py,放在apache的cgi-bin目录下:#!/usr/bin/Pythonimport cgidef main():print "Content-type: text/html\n"form = cgi.FieldStorage()if form.has_key("ServiceCode") and form["ServiceCode"].value != "":print " Hello...

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

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