C# - request.GetResponse()
本文关键字:GetResponse request | 更新日期: 2023-09-27 18:11:06
我正在制作一个web浏览器,我正试图在选项卡上显示一个图标。我在写代码时遇到了一些麻烦。
System.Net.HttpWebResponse response = request.GetResponse();
特别是,这里是完整的代码:
int selpage = tabControl1.SelectedIndex;
dynamic iconURL = web.Url.AbsoluteUri + "/favicon.ico";
System.Net.WebRequest request = System.Net.HttpWebRequest.Create(iconURL);
System.Net.HttpWebResponse response = request.GetResponse();
System.IO.Stream stream = response.GetResponseStream();
dynamic mimage = Image.FromStream(stream);
tabControl1.TabPages[selpage].ImageIndex = mimage;
下面是它提供给我的错误:
错误CS0266不能隐式转换类型System.Net.WebResponse"System.Net.HttpWebResponse"。存在显式转换)
请尝试:
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
如果你用的是。net 4.5你应该看看HttpClient