C#webrequest或webclient问题

C#webrequest或webclient问题,c#,webrequest,C#,Webrequest,我正在我的应用程序中实现一个论坛板。 使用webrequest对象下载页面,然后将其应用于web浏览器控件的文档文本(必须通过webrequest访问页面),并且缺少元素和正常广告。我怎样才能解决这个问题 这是我正在使用的函数: private void Navigate(string url, string credentials, ref WebBrowser wbBrowser) { WebRequest req;

我正在我的应用程序中实现一个论坛板。 使用webrequest对象下载页面,然后将其应用于web浏览器控件的文档文本(必须通过webrequest访问页面),并且缺少元素和正常广告。我怎样才能解决这个问题

这是我正在使用的函数:

        private void Navigate(string url, string credentials, ref WebBrowser wbBrowser)
        {
            WebRequest req;

            WebProxy proxy;

            WebResponse response;

            StreamReader sr;

            int index;

            string  username,
                    password,
                    ipAddress,
                    temp;


            index = 0;

            try
            {
                for (int i = 0; i < 2; i++)
                    index = credentials.IndexOf(':', index + 1);

                if (index != -1)
                {
                    ipAddress = credentials.Remove(index, credentials.Length - index);

                    temp = credentials.Remove(0, index + 1);

                    index = temp.IndexOf(':');

                    username = temp.Remove(index, temp.Length - index);
                    password = temp.Remove(0, index + 1);

                    proxy = new WebProxy(ipAddress, true);
                    proxy.Credentials = new NetworkCredential(username, password);

                    req = WebRequest.Create(url);
                    req.Proxy = proxy;

                    response = req.GetResponse();


                    sr = new StreamReader(response.GetResponseStream());

                    temp = sr.ReadToEnd();

                    index = temp.IndexOf("<head>");

                    if (index != -1)
                        temp = temp.Insert(index + 6, "<base href=\"" + url + " \" />");

                    mainDocument = null;

                    wbBrowser.DocumentText = temp;

                    while (mainDocument == null)
                        Thread.Sleep(250);
                }
            }
            catch (Exception x)
            {
                MessageBox.Show(x.ToString());
            }
        }
private void导航(字符串url、字符串凭据、ref WebBrowser wbBrowser)
{
网络请求请求;
网络代理;
网络响应;
StreamReader sr;
整数指数;
字符串用户名,
密码,
IP地址,
临时雇员
指数=0;
尝试
{
对于(int i=0;i<2;i++)
index=credentials.IndexOf(“:”,index+1);
如果(索引!=-1)
{
ipAddress=凭证.Remove(索引,凭证.Length-index);
临时=凭据。删除(0,索引+1);
索引=临时索引(':');
用户名=临时删除(索引,临时长度-索引);
密码=临时删除(0,索引+1);
proxy=新的WebProxy(ipAddress,true);
proxy.Credentials=新的网络凭据(用户名、密码);
req=WebRequest.Create(url);
请求代理=代理;
response=req.GetResponse();
sr=新的StreamReader(response.GetResponseStream());
temp=sr.ReadToEnd();
指数=温度指数(“”);
如果(索引!=-1)
温度=插入温度(索引+6“”);
mainDocument=null;
wbBrowser.DocumentText=temp;
while(mainDocument==null)
睡眠(250);
}
}
捕获(异常x)
{
Show(x.ToString());
}
}
我使用它作为导航(“页面”,“ip:端口:用户名:密码”,参考demoBrowser)

我将引用我自己的话,因为它在不处理代理时非常有意义:

这里的问题是,您通过WebRequest接收的HTML包含指向当前上下文中不存在的CSS文件的相对路径。您可以通过在节中添加以下标记来修改HTML:

<base href="http://domainname.com/" />


之后,WebBrowser控件解析此标记中域的相对CSS路径。

显示用于生成webRequest/Response的代码?是的,它确实显示了样式,但我在论坛底部的adsense块在源代码中完全缺失。这就是我现在需要的帮助。你知道如何启动和运行它吗?