Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass local path to HttpWebRequest

Tags:

c#

I need to pass local path to HttpWebRequest in c#. i have test.xml in my c drive and i need get that xml file in HttpWebRequest. but it throws exception in

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

line "Invalid URI: The Authority/Host could not be parsed."

my coding->

string urlServ = "file:\\c:\\test.xml";
  try
   {             
      HttpWebRequest rqst = (HttpWebRequest)HttpWebRequest.Create(Uri.EscapeUriString(urlServ));
      rqst.KeepAlive = false;
   }
catch{}
like image 324
DevT Avatar asked May 02 '26 11:05

DevT


1 Answers

I believe a file: URI is supposed to be created with forward-slashes, not back slashes. So, use this:

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

I noticed when I typed it into my browser with backslashes, FF converted it to forward slashes for me.

like image 115
Andrew Barber Avatar answered May 05 '26 02:05

Andrew Barber