繁体   English   中英

WebRequest.Create(uri)与本地html文件

[英]WebRequest.Create(uri) with a local html file

我有一个使用WebBrowser的应用程序。 此webBrowser加载本地页面(file://PathOfPage.html)。

我希望能够对此页面进行请求,因为我需要在该页面中获取/设置Cookie。

问题是,如果我使用类似uri的“ file:// Program Files /..../ page.html”之类的内容,则WebRequest.Create(uri)会由于该uri给我一个UnSupportedException。

我的代码:

Uri uri = webBrowser1.Url;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string cookie = response.Headers.Get("Cookie");

有什么建议么? 谢谢!

检查您的Uri格式(file:///),还有助于指定其相对还是绝对格式(您也会因此而获得异常)这是一些示例:var uri = new Uri(“ file:// C / thing /otherthing/whatever.html",UriKind.Absolute);

希望有帮助! 汤姆

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM