Python发送http请求 发表于 2017-02-04 | 分类于 Python | | 阅读次数: 在Python中,发送http请求的简单教程 用urllib2发送http请求123456789101112131415# -*- coding=utf-8 -*-import urllib2import jsonapiUrl = 'http://XXX.XXX'param1 = XXXparam2 = XXXparam3 = XXXparams = {'param1': param1, 'param2': param2, 'param3': param3}jParams = json.dumps(params)headers = {'Content-Type': 'application/json'} # 设置数据为json格式,很重要request = urllib2.Request(url=apiUrl, headers=headers, data=jParams)response = urllib2.urlopen(request)print response.getcode() # 请求状态,200为成功print response.read() # 返回的body -------------本文结束感谢您的阅读-------------