简体   繁体   English

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

[英]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.

相关问题 .Net WebRequest.Create解码编码的URI - .Net WebRequest.Create Decoding encoded URI C#,WebRequest.Create(String URI)返回null - C#, WebRequest.Create(String URI) returns null 在WebParts的RenderControl()内部使用WebRequest.Create - Using WebRequest.Create inside RenderControl() for WebParts 'WebRequest.Create(string)' 已过时:'WebRequest,改用 HttpClient。' - 'WebRequest.Create(string)' is obsolete: 'WebRequest, Use HttpClient instead.' WebRequest.Create(“ URL”)的可能方式总是失败? - Possible ways of WebRequest.Create(“URL”) always failed? c#是WebRequest.Create给我的URL编码吗? - c# is WebRequest.Create gives me a URL encoded? WebRequest.Create抛出IOException“指定的注册表项不存在。” - WebRequest.Create throws IOException “The specified registry key does not exist.” WebRequest.create在.NET 3.5类库中引起SecurityException,但在.net 4.5中不引起 - WebRequest.create causing SecurityException in a .NET 3.5 class lib, but not in .net 4.5 WebRequest.Create抛出“Value不能为null。 参数名称:str“exception - WebRequest.Create throws “Value cannot be null. Parameter name: str” exception 从 silverlight 导航到本地文件 Uri? 例外 - Navigate to local file Uri from silverlight? Exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM