【发布时间】:2013-03-16 11:38:36
【问题描述】:
我想知道一些在使用 PyCurl 发出请求时捕获和访问回复的标头信息的方法:
c = pycurl.Curl()
c.setopt(c.URL,'MY_URL')
c.setopt(c.COOKIEFILE,'cookies')
c.setopt(c.COOKIE,'cookies')
c.setopt(c.POST,1)
c.setopt(c.POSTFIELDS,'MY AUTH VALUES')
c.setopt(c.VERBOSE, True)
b = StringIO.StringIO()
c.setopt(c.WRITEFUNCTION, b.write)
c.perform()
回复将以格式正确的 JSON 格式写入缓冲区 b。
我希望恢复回复中“Location”标头的值。
尝试使用 curl 时,可以在详细输出中看到此值:
[... Curl output ...]
> GET XXXXXXXXX
[... Request ...]
[... Curl output ...]
< HTTP/1.1 302 Found
[... Other headers ...]
< Location: YYYYYYYYYYYYYYY
[... Rest of reply ...]
如何从 python 中恢复 Location 标头的值?
【问题讨论】: