Home  >  Article  >  Backend Development  >  python通过post提交数据的方法

python通过post提交数据的方法

WBOY
WBOYOriginal
2016-06-10 15:13:121171browse

本文实例讲述了python通过post提交数据的方法。分享给大家供大家参考。具体实现方法如下:

# -*- coding: cp936 -*-
import urllib2
import urllib
def postHttp(name=None,tel=None,address=None,
       price=None,num=None,paytype=None,
       posttype=None,other=None):
  url="http://www.xxx.com/dog.php"
  #定义要提交的数据
  postdata=dict(name=name,tel=tel,address=address,price=price,
         num=num,paytype=paytype,posttype=posttype,other=other)
  #url编码
  postdata=urllib.urlencode(postdata)
  #enable cookie
  request = urllib2.Request(url,postdata)
  response=urllib2.urlopen(request)
  print response

调用函数:

复制代码 代码如下:
postHttp('姓名','电话','地址','230元', '1','货到付款','EMS国内邮政特快专递','饥渴长耳兔-国际品牌')

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn