Fiddler无法捕获对localhost的请求
当我正常运行我的Python代码时:
batch_request = BatchHttpRequest(batch_uri = "http://localhost:12345/api/batch")
batch_request.add(get_customers)
batch_request.execute()
Fiddler没有捕捉到请求。
当我把batch_uri
改成localhost.fiddler
时,我得到了:
ServerNotFoundError: Unable to find the server at localhost.fiddler
对ipv4.fiddler
也是一样。
当我把batch_uri
改成我的电脑名称pc-21
时,我得到了:
<HttpError 400 when requesting http://pc-21:12345/api/batch returned "Bad Request">
我尝试在Fiddler中添加了以下规则:
static function OnBeforeRequest(oSession:Fiddler.Session){
if (oSession.HostnameIs("MYAPP")){
oSession.host = "127.0.0.1:8081";
}
}
但这也给了我一个找不到服务器的错误。
而且这些请求在Fiddler中仍然没有出现。
有没有人有什么想法??
编辑
根据EricLaw的建议,我让以下代码在Fiddler中正常工作并被捕捉到了:
proxy = ProxyInfo(proxy_type=socks.PROXY_TYPE_HTTP_NO_TUNNEL, proxy_host='127.0.0.1', proxy_port=8888)
http = Http(proxy_info=proxy)
get_customers = HttpRequest(http, print_complete, "http://localhost:65200/api/Customers", method="GET", headers={"Content-Type": "application/http; msgtype=request"})
batch_request = BatchHttpRequest(batch_uri = "http://localhost:65200/api/batch")
batch_request.add(get_customers, callback=print_complete)
try:
batch_request.execute()
except HttpError, e:
print "{0}".format(e)
1 个回答
2
你的Python代码没有设置使用Fiddler作为代理,这就是为什么localhost.fiddler
这个主机名无法识别的原因。这个虚拟主机名只有在通过Fiddler发送请求时才会存在。
你在Python中使用的是哪个HTTP对象?你需要查看它的文档,了解如何将它的代理设置为127.0.0.1:8888
。比如说,可以参考这个链接:使用urllib2的代理