好久没写博客了,想重新开始、继续积累。
最近在使用 Fiddler 分析一个应用,出现了如下错误:
[Fiddler] ReadResponse() failed: The server did not return a complete response for this request.
对这块不是特别熟,一时半会没有头绪。按照该错误说明来讲,应该是服务器没有发送数据。这原因可就多了去了,一般是服务器认为不应该进行响应操作。在网上找了些资料,有说权限设置不正确,但在我这不应存在此情况,我只有在挂上 Fiddler 的时候才出现应用无法和服务器通讯的情况,那么就此断定是 Fiddler 的问题。
找了一会 Fiddler 的设置,仍然无法解决,突然看见应用发的包:
POST HTTP/1.1
Content-Length: 38
Content-Type: application/x-www-form-urlencoded
Host: (主机名)
Connection: Keep-Alive
User-Agent: android-async-http/1.4.4 (http://loopj.com/android-async-http)
Accept-Encoding: gzip
(数据)
发现在 Header 的首行没有地址,这个应用写的也真是奇葩…… 不知道是否符合 HTTP 规范。找到 FiddlerScript,摸索着在 OnBeforeRequest 函数中添加如下代码:
// 防止某些服务器出错
if (oSession.url == "http://(主机)")
{
oSession.url = "http://(主机)/";
}
兴高采烈地去测试,依然返回 504 Fiddler 相关的错误,以及 400 BadRequest. 由于不知道 Session::url 的格式,可能问题出在这。
先注释掉,然后换了一种方法,在 AutoResponder 里添加 Rule, 进行重定向,解决了问题。
后记
在 Fiddler Script 的例子文档中,找到了如下用法:
if (oSession.url=="www.example.com/live.js") {
oSession.url = "dev.example.com/workinprogress.js";
}
原来是不需要加 "http://" 的……
查询 RFC2616,5.1.2 节,有如下描述:
5.1.2 Request-URI
Request-URI = "*" | absoluteURI | abs_path | authority
Note that the absolute path cannot be empty; if none is present in the original URI, it MUST be given as "/" (the server root).
根据这段描述, 该应用发出的请求并不符合规范。