C# .NET - Rest,Webservice - Asked By abinav shankar on 01-Nov-11 07:30 AM

hi
 
i have used the following method to send the file to validate the url but i am not getting any responce and my browser is in connecting stage and my code is as follows pl tell me how to solve it
 
my code is as follows
 
          string url = "http://www.inspire-geoportal.eu/INSPIREValidatorService/resources/validation/inspire";
          HttpWebRequest webRequest = WebRequest.Create(url) as HttpWebRequest;
          webRequest.Headers.Clear();
          webRequest.Headers.Add("Authorization", "text/html");
          webRequest.Method = "POST";
          webRequest.PreAuthenticate = true;
          webRequest.ContentType = "application/xml";
          webRequest.Credentials = CredentialCache.DefaultNetworkCredentials ;//.DefaultCredentials;
          webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
          webRequest.Timeout = 150000;
          // Create POST data and convert it to a byte array.
          webRequest.ContentLength = formData.Length;
          WebResponse webResponse = null;
          StreamReader objSR;
          System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
          Stream objStream;
          string sResponse;
          webResponse = (HttpWebResponse)webRequest.GetResponse();
objStream = webResponse.GetResponseStream();
          objSR = new StreamReader(objStream, encode, true);
          //<<sResponse doesn't contain Unicode char values>>
          sResponse = objSR.ReadToEnd();
          Response.Write(sResponse);

Kirtan Patel replied to abinav shankar on 01-Nov-11 08:09 AM
try below code 

Untitled document
string url = "http://www.inspire-geoportal.eu/INSPIREValidatorService/resources/validation/inspire";
HttpWebRequest webRequest = WebRequest.Create(url) as HttpWebRequest;
 
webRequest.Headers.Clear();
webRequest.Headers.Add("Authorization", "text/html");
webRequest.Method = "POST";
webRequest.PreAuthenticate = true;
webRequest.ContentType = "application/xml";
webRequest.Credentials = CredentialCache.DefaultNetworkCredentials ;//.DefaultCredentials;
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
webRequest.Timeout = 150000;
// Create POST data and convert it to a byte array.
webRequest.ContentLength = formData.Length;
 
HttpWebResponse = (HttpWebResponse)webRequest.GetResponse();
// Get the stream associated with the response.
Stream receiveStream = webResponse.GetResponseStream();
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);
 
Console.WriteLine ("Response stream received.");
Console.WriteLine (readStream.ReadToEnd ());
response.Close ();
readStream.Close ();