www.ywwj.net > 如何用Python写一个http post请求

如何用Python写一个http post请求

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

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

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

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

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

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

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

测试用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 requests url = 'http://example.com/' requests.post(url, data={'key': 'value'})

网站地图

All rights reserved Powered by www.ywwj.net

copyright ©right 2010-2021。
www.ywwj.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com