【发布时间】:2011-02-02 08:45:24
【问题描述】:
我在通过套接字执行 HTTP 请求时遇到了奇怪的行为,这里是请求:
POST https://example.com:443/service/XMLSelect HTTP/1.1
Content-Length: 10926
Host: example.com
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 1.0.3705)
Authorization: Basic XXX
SOAPAction: http://example.com/SubmitXml
稍后会出现我的请求正文,其中包含给定的内容长度。 之后我收到类似的东西:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Tue, 30 Mar 2010 06:13:52 GMT
所以这里似乎一切都很好。我从网络流中读取了所有内容并成功接收到响应。但是我正在对开关进行轮询的套接字是这样的模式:
write ( i write headers and request here )
read ( after headers sent i begin to receive response )
write ( STRANGE BEHAVIOUR HERE. WHY? here i send nothing really )
read ( here it switches to read back again )
最后两步可以重复多次。所以我想问一下socket的模式改变是什么导致的?在这种情况下,这不是一个大问题,但是当我在我的请求中使用 gzip 压缩(不知道它是如何相关的)并要求服务器像这样向我发送 gzip 响应时:
POST https://example.com:443/service/XMLSelect HTTP/1.1
Content-Length: 1076
Accept-Encoding: gzip
Content-Encoding: gzip
Host: example.com
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 1.0.3705)
Authorization: Basic XXX
SOAPAction: http://example.com/SubmitXml
我收到这样的回复:
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Encoding: gzip
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Tue, 30 Mar 2010 07:26:33 GMT
2000
�
我收到一个块大小和 GZIP 标头,一切正常。这就是我可怜的小插座同时发生的事情:
write ( i write headers and request here )
read ( after headers sent i begin to receive response )
write ( STRANGE BEHAVIOUR HERE. And it finally sits here forever waiting for me to send something! But if i refer to HTTP I don't have to send anything more! )
它与什么有关?它要我发送什么?是远程 Web 服务器的问题还是我遗漏了什么?
PS 所有实际的服务参考和登录名/密码都替换为假的:)
【问题讨论】:
-
小点,但示例 URL 应使用 RFC2606 保留域之一 [rfc-editor.org/rfc/rfc2606.txt] 例如 example.com - 如果有人复制/粘贴示例,保证永远不会指向活动域在任何可以做任何事情的地方编写代码
-
Ops,对不起,替换为正确的 :) 我的问题呢?