如果您的服务器期望POST请求为json,则您需要添加标头,并为请求序列化数据…
Python 2.x
import jsonimport urllib2data = { 'ids': [12, 3, 4, 5, 6]}req = urllib2.Request('http://example.com/api/posts/create')req.add_header('Content-Type', 'application/json')response = urllib2.urlopen(req, json.dumps(data))Python 3.x
如果不指定标题,它将是默认
application/x-www-form-urlenpred类型。



