|
View:
New views
8 Messages
—
Rating Filter:
Alert me
|
|
|
[CPyUG:41451] 关于urllib2中的Keep-Alive及请教好用的htt |
|
|
|
[CPyUG:41454] Re: 关于urllib2中的Keep-Alive及请教好用的htt |
|
|
|
[CPyUG:41455] Re: 关于urllib2中的Keep-Alive及请教好用的htt |
| # We want to make an HTTP/1.1 request, but the
addinfourl # class isn't prepared to deal with a persistent connection. # It will try to read all remaining data from the socket, # which will block while the server waits for the next request. # So make sure the connection gets closed after the (only) # request. headers["Connection"] = "close" headers = dict( (name.title(), val) for name, val in headers.items()) try: h.request(req.get_method(), req.get_selector(), req.data, headers) r = h.getresponse() except socket.error, err: # XXX what error? raise URLError(err) |
urllib2 中是什么地方的硬编码导致和keep-alive不兼容?
这个问题去年有人讨论过,我也是搜索去年的邮件搜出来的相关信息。
我安装的是python2.5,在 urllib2.py 文件的第 1068 行。
也就是 AbstractHTTPHandler 这个类的 do_open 方法中。
注释说,addinfourl 类对持久链接没准备好。。。
代码片段如下:
# We want to make an HTTP/1.1 request, but the addinfourl
# class isn't prepared to deal with a persistent connection.
# It will try to read all remaining data from the socket,
# which will block while the server waits for the next request.
# So make sure the connection gets closed after the (only)
# request.
headers["Connection"] = "close"
headers = dict(
(name.title(), val) for name, val in headers.items())
try:
h.request(req.get_method(), req.get_selector(), req.data, headers)
r = h.getresponse()
except socket.error, err: # XXX what error?
raise URLError(err)
fluke.l 写道:urllib2 中是什么地方的硬编码导致和keep-alive不兼容?
如果你是windows平台,通过python调COM好了,连Cookie都不用自己管理,行为和IE一模一样。
而且Connection: Keep-Alive
代码大概像这样的:
http = win32com.client.Dispatch("msxml2.xmlhttp")
http.Open("POST",url,False)
http.send(q)
2008/2/27 hechu <hcpython@...>:
这个问题去年有人讨论过,我也 是搜索去年的邮件搜出来的相关信息。
我安装的是python2.5,在 urllib2.py 文件的第 1068 行。
也就是 AbstractHTTPHandler 这个类的 do_open 方法中。
注释说,addinfourl 类对持久链接没准备好。。。
代码片段如下:
# We want to make an HTTP/1.1 request, but the addinfourl
# class isn't prepared to deal with a persistent connection.
# It will try to read all remaining data from the socket,
# which will block while the server waits for the next request.
# So make sure the connection gets closed after the (only)
# request.
headers["Connection"] = "close"
headers = dict(
(name.title(), val) for name, val in headers.items())
try:
h.request(req.get_method(), req.get_selector(), req.data, headers)
r = h.getresponse()
except socket.error, err: # XXX what error?
raise URLError(err)
fluke.l 写道:urllib2 中是什么地方的硬编码导致和keep-alive不兼容?
谢谢指导。请问一下,MSXML的手册在什么地方有,我要仔细看看说明。
我的系统是Windows XP SP2,打齐了补丁,所以MSXML组件有安装升级,但是在本机搜索了一下,没有相关的帮助。
谢谢!
junyi sun 写道:如果你是windows平台,通过python调COM好了,连Cookie都不用自己管理,行为和IE一模一样。
而且Connection: Keep-Alive
代码大概像这样的:
http = win32com.client.Dispatch("msxml2.xmlhttp")
http.Open("POST",url,False)
http.send(q)
2008/2/27 hechu <hcpython@...>:
这个问题去年有人讨论过,我也 是搜索去年的邮件搜出来的相关信息。
我安装的是python2.5,在 urllib2.py 文件的第 1068 行。
也就是 AbstractHTTPHandler 这个类的 do_open 方法中。
注释说,addinfourl 类对持久链接没准备好。。。
代码片段如下:
# We want to make an HTTP/1.1 request, but the addinfourl
# class isn't prepared to deal with a persistent connection.
# It will try to read all remaining data from the socket,
# which will block while the server waits for the next request.
# So make sure the connection gets closed after the (only)
# request.
headers["Connection"] = "close"
headers = dict(
(name.title(), val) for name, val in headers.items())
try:
h.request(req.get_method(), req.get_selector(), req.data, headers)
r = h.getresponse()
except socket.error, err: # XXX what error?
raise URLError(err)
fluke.l 写道:urllib2 中是什么地方的硬编码导致和keep-alive不兼容?
XmlHttp对象参考:
属性:
onreadystatechange* 指定当readyState属性改变时的事件处理句柄。只写
readyState 返回当前请求的状态,只读.
responseBody 将回应信息正文以unsigned byte数组形式返回.只读
responseStream 以Ado Stream对象的形式返回响应信息。只读
responseText 将响应信息作为字符串返回.只读
responseXML 将响应信息格式化为Xml Document对象并返回,只读
status 返回当前请求的http状态码.只读
statusText 返回当前请求的响应行状态,只读
* 表示此属性是W3C文档对象模型的扩展.
方法:
abort 取消当前请求
getAllResponseHeaders 获取响应的所有http头
getResponseHeader 从响应信息中获取指定的http头
open 创建一个新的http请求,并指定此请求的方法、URL以及验证信息(用户名/密码)
send 发送请求到http服务器并接收回应
setRequestHeader 单独指定请求的某个http头
statusText 返回当前请求的响应行状态,只读
* 表示此属性是W3C文档对象模型的扩展.
方法:
abort 取消当前请求
2008/2/27 hechu <hcpython@...>:
谢谢指导。请问一下,MSXML的手册在什么地方有,我要仔细看 看说明。
我的系统是Windows XP SP2,打齐了补丁,所以MSXML组件有安装升级,但是在本机搜索了一下,没有相关的帮助。
谢谢!
junyi sun 写道:如果你是windows平台,通过python调COM好了,连Cookie都不用自己管理, 行为和IE一模一样。
而且Connection: Keep-Alive
代码大概像这样的:
http = win32com.client.Dispatch("msxml2.xmlhttp")
http.Open("POST",url,False)
http.send(q)
2008/2/27 hechu <hcpython@...>:
这个问题去年有人讨论 过,我也 是搜索去年的邮件搜出来的相关信息。
我安装的是python2.5,在 urllib2.py 文件的第 1068 行。
也就是 AbstractHTTPHandler 这个类的 do_open 方法中。
注释说,addinfourl 类对持久链接没准备好。。。
代码片段如下:
# We want to make an HTTP/1.1 request, but the addinfourl
# class isn't prepared to deal with a persistent connection.
# It will try to read all remaining data from the socket,
# which will block while the server waits for the next request.
# So make sure the connection gets closed after the (only)
# request.
headers["Connection"] = "close"
headers = dict(
(name.title(), val) for name, val in headers.items())
try:
h.request(req.get_method(), req.get_selector(), req.data, headers)
r = h.getresponse()
except socket.error, err: # XXX what error?
raise URLError(err)
fluke.l 写道:urllib2 中是什么地方的硬编码导致和keep-alive不兼容?
| Free embeddable forum powered by Nabble | Forum Help |