English 中文(简体)
通过本地路径到 HttpWeb 请求
原标题:pass local path to HttpWebRequest
  • 时间:2012-05-24 04:31:58
  •  标签:
  • c#

我需要通过本地路径到 C# 中的 HttpWeb 请求 。 I have test. xml in my c 驱动器中, 我需要在 HttpWebRequest 中获取 xml 文件。 但是它在其中排除了例外 。

HttpWebRequest rqst = (HttpWebRequest)HttpWebRequest.Create(Uri.EscapeUriString(urlServ))

无效 URI: 无法解析权限/ 住家 。

我的编码 & gt;

string urlServ = "file:\c:\test.xml";
  try
   {             
      HttpWebRequest rqst = (HttpWebRequest)HttpWebRequest.Create(Uri.EscapeUriString(urlServ));
      rqst.KeepAlive = false;
   }
catch{}
最佳回答

我相信一个 file: URI 应该是用前鞭而不是后鞭来创建的。 因此, 请使用此选项 :

string urlServ = "file:///c:/test.xml";

我注意到我用反鞭子打入浏览器时 FF把它转换成前鞭子

问题回答

您应该使用 < code> WebRequest.Create( uri) - 这将自动创建基于 URI 类型( 例如文件、 http 等) 的右对象。 现在您可以对真实网页或本地测试文件使用相同的代码 。

我在FileWebResources 的文件中看到了这一点:

Do not use the FileWebRequest constructor. Use the WebRequest.Create method to initialize new instances of the FileWebRequest class. If the URI scheme is file://, the Create method returns a FileWebRequest object.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签