yas*_*sar 2 python curl urllib2
据我所知,我需要使用url编码的内容与urllib一起发布.使用urllib发布时是否可以使用application/json内容类型?
不使用urllib,因为您需要设置Content-type标头,而urllib不提供这样做的方法.你可以用urllib2来做(但也不urlopen()是用更多的意思"打开带有url的文件"而不是提交数据):
import urllib2
req = urllib2.Request('http://www.example.com/', data="abc", headers={'Content-type': 'text/plain'})
r = urllib2.urlopen(req)
Run Code Online (Sandbox Code Playgroud)
就个人而言,我更喜欢httplib2(3d派对)作为http客户端库.