title: System.Net.WebException: The remote server returned an error: (405) Method Not Allowed .exception occurred during the execution of the web request
body: <p>When I ran my web application code I got this error on this line.</p>
  
  <pre><code>using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()){}
  </code></pre>
  
  <p>Actually when I ran my url directly on browser.It will give proper o/p but when I ran my url in code. It will give exception.</p>
  
  <p>Here MyCode is :-</p>
  
  <pre><code>string service = "http://api.ean.com/ean-services/rs/hotel/";
  
  string version = "v3/";
  string method = "info/";
  string hotelId1 = "188603";
  
  int hotelId = Convert.ToInt32(hotelId1);
  
  
  string otherElemntsStr = "&amp;cid=411931&amp;minorRev=[12]&amp;customerUserAgent=[hotel]&amp;locale=en_US&amp;currencyCode=INR";
  
  string apiKey = "tzyw4x2zspckjayrbjekb397";
  string sig = "a6f828b696ae6a9f7c742b34538259b0";
  
  string url = service + version + method + "?&amp;type=xml" + "&amp;apiKey=" + apiKey + "&amp;sig=" + sig + otherElemntsStr + "&amp;hotelId=" + hotelId;
  
  
  
   HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url) as HttpWebRequest;
  
   request.Method = "POST";
   request.ContentType = "text/xml";
   request.ContentLength = 0;
  
   XmlDocument xmldoc = new XmlDocument();
  
   using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
   {
         StreamReader responsereader = new StreamReader(response.GetResponseStream());
  
         var responsedata = responsereader.ReadToEnd();
         xmldoc = (XmlDocument)JsonConvert.DeserializeXmlNode(responsedata);
         xmldoc.Save(@"D:\FlightSearch\myfile.xml");
         xmldoc.Load(@"D:\FlightSearch\myfile.xml");
  
         DataSet ds = new DataSet();
         ds.ReadXml(Request.PhysicalApplicationPath + "myfile.xml");
         GridView1.DataSource = ds.Tables["HotelSummary"];
         GridView1.DataBind();            
    }   
  </code></pre>