python实现curl功能

之前写过一篇文章关于python CURL模块的,在这里我们从urllib来实现同样的功能。具体代码如下:

import urllib
import urllib2
import json

#发起请求的url
post_url = 'http://www.test.baidu.com';

postData  = {'a':'aaa','b':'bbb','c':'ccc','d':'ddd'}
#json序列化
data = json.dumps(postData)
	
req = urllib2.Request(post_url)
response = urllib2.urlopen(req,urllib.urlencode({'sku_info':data}))

#打印返回值
print response.read()

 对方接收sku_info参数即可,然后解析json参数

原文地址:https://www.cnblogs.com/gide/p/6069382.html