简体   繁体   中英

WebRequest.Create(uri) with a local html file

I have an application that uses an WebBrowser. This webBrowser load local pages (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.

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.

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);

Hope this help! Tom

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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