[英]WebRequest.Create(uri) with a local html file
I have an application that uses an WebBrowser. 我有一个使用WebBrowser的应用程序。 This webBrowser load local pages (file://PathOfPage.html). 此webBrowser加载本地页面(file://PathOfPage.html)。
I want to be able to do a request to this page because of I need to get/set cookies in that page. 我希望能够对此页面进行请求,因为我需要在该页面中获取/设置Cookie。
The problem is that if i use like uri something like this "file://Program Files/..../page.html", WebRequest.Create(uri) give me an UnSupportedException because of that uri. 问题是,如果我使用类似uri的“ file:// Program Files /..../ page.html”之类的内容,则WebRequest.Create(uri)会由于该uri给我一个UnSupportedException。
My code: 我的代码:
Uri uri = webBrowser1.Url;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string cookie = response.Headers.Get("Cookie");
Any suggestions? 有什么建议么? Thanks! 谢谢!
Check your Uri format (file:///), also helps to specify if its relative or absolute (you well get an exception for that too) Here is some example: var uri = new Uri("file://C/thing/otherthing/whatever.html", UriKind.Absolute); 检查您的Uri格式(file:///),还有助于指定其相对还是绝对格式(您也会因此而获得异常)这是一些示例:var uri = new Uri(“ file:// C / thing /otherthing/whatever.html",UriKind.Absolute);
Hope this help! 希望有帮助! Tom 汤姆
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.