POST 响应长度非零,但读取为空
我正在关注此 Virtuoso Web 服务示例。我的 POST 响应的 .length 不为零,但 .read() 为空。仅当 POST 成功时才会发生这种情况。如果我故意犯错误,我将得到一个非零的 .read()。
import httplib
url = 'lod.openlinksw.com'
xmlString = '''<?xml version="1.0"?>
<query xmlns="http://openlinksw.com/services/facets/1.0" inference="" same-as="">
<text>Seattle Mariners traveled all the way to Japan to watch</text>
<view type="text" limit="20" offset=""/>
</query>'''
xml = open('a.xml','w')
xml.write(xmlString)
xml.close()
xml = open('a.xml')
headers = {'Content-Type': 'text/xml',}
conn = httplib.HTTPConnection(url)
conn.request("POST", "/fct/service", xml, headers)
re = conn.getresponse()
conn.close()
data = re.read()
print re.reason, re.status, '| len:', re.length, '| read() len:', len(data)
返回...
OK 200 | len: 19902 | read() len: 0
如果您故意修改 XML(例如“query”>>“queryzzz”)...
Internal Server Error 500 | len: 0 | read() len: 340
我确信我只是在做一些愚蠢的事情。我的 19902 字节响应在哪里?
I am following this Virtuoso Web Service example. My the response from a POST has a non-zero .length, but .read() is empty. This only happens when POST is successful. If I intentionally make a mistake I will get a non-zero .read().
import httplib
url = 'lod.openlinksw.com'
xmlString = '''<?xml version="1.0"?>
<query xmlns="http://openlinksw.com/services/facets/1.0" inference="" same-as="">
<text>Seattle Mariners traveled all the way to Japan to watch</text>
<view type="text" limit="20" offset=""/>
</query>'''
xml = open('a.xml','w')
xml.write(xmlString)
xml.close()
xml = open('a.xml')
headers = {'Content-Type': 'text/xml',}
conn = httplib.HTTPConnection(url)
conn.request("POST", "/fct/service", xml, headers)
re = conn.getresponse()
conn.close()
data = re.read()
print re.reason, re.status, '| len:', re.length, '| read() len:', len(data)
Return...
OK 200 | len: 19902 | read() len: 0
If you intentionally malform the XML (e.g. "query" >> "queryzzz")...
Internal Server Error 500 | len: 0 | read() len: 340
I am sure I am just doing something silly. Where's my 19902 byte response?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改
为
您需要在关闭连接之前读取数据,否则任何尚未传输的字节都将丢失。
Change
to
You need to read the data before closing the connection or any not yet transferred bytes will be lost.