Titanium Web代理无法加载图像

时间:2016-06-24 16:23:53

标签: c# proxy

我正在研究用c#编写的笔测试应用程序,我正在使用Titanium代理。我已经能够获得html,css,js和其他内容类型。虽然我无法显示图像。这有什么秘密吗?

github上钛的示例代码有一个if只允许text / html通过。这是该网站的代码,我刚刚添加了其他一些ifs。

if (e.WebSession.Request.Method == "GET" || e.WebSession.Request.Method == "POST")
        {
            if (e.WebSession.Response.ResponseStatusCode == "200")
            {
                if (e.WebSession.Response.ContentType!=null && e.WebSession.Response.ContentType.Trim().ToLower().Contains("text/html"))
                {
                    byte[] bodyBytes = await e.GetResponseBody();
                    await e.SetResponseBody(bodyBytes);

                    string body = await e.GetResponseBodyAsString();
                    await e.SetResponseBodyString(body);
                }
            }
        }

我尝试添加一个else,使用与上面的主体完全相同的代码来捕获其他所有内容但是图像似乎永远不会在网站中加载,尽管所有CSS,JS和HTML似乎都能正常工作。

这是Titanium web proxy github页面的链接。 https://github.com/justcoding121/Titanium-Web-Proxy

1 个答案:

答案 0 :(得分:1)

e.WebSession.Response.ContentType.Trim().ToLower().Contains("text/html")

图片具有不同的内容类型。您应该删除上面的检查,然后使用适当的内容类型。之后,读取字节并使用content-type header中指定的格式将其保存为图像。