System.Net.WebException: The remote server returned an error: (405) Method Not Allowed .exception occurred during the execution of the web request

Posted by user88 on Stack Overflow See other posts from Stack Overflow or by user88
Published on 2013-01-22T11:55:36Z Indexed on 2013/11/07 9:55 UTC
Read the original article Hit count: 979

Filed under:
|

When I ran my web application code I got this error on this line.

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()){}

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.

Here MyCode is :-

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 = "&cid=411931&minorRev=[12]&customerUserAgent=[hotel]&locale=en_US&currencyCode=INR";

string apiKey = "tzyw4x2zspckjayrbjekb397";
string sig = "a6f828b696ae6a9f7c742b34538259b0";

string url = service + version + method + "?&type=xml" + "&apiKey=" + apiKey + "&sig=" + sig + otherElemntsStr + "&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();            
  }   

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about web-services