简体   繁体   English

远程服务器返回错误:(405) 在 expedia api 调用中不允许方法

[英]The remote server returned an error: (405) Method Not Allowed in expedia api call

string url = "https://book.api.ean.com/ean-services/rs/hotel/v3/avail?cid=55505&minorRev=30&apiKey=bsm4nqpcawnppkpwjkej2rfq&locale=en_US&currencyCode=INR&xml=%3CHotelRoomAvailabilityRequest%3E%0A%20%20%20%20%3ChotelId%3E106347%3C%2FhotelId%3E%0A%20%20%20%20%3CarrivalDate%3E9%2F29%2F2015%3C%2FarrivalDate%3E%0A%20%20%20%20%3CdepartureDate%3E10%2F1%2F2015%3C%2FdepartureDate%3E%0A%20%20%20%20%3CincludeDetails%3Etrue%3C%2FincludeDetails%3E%0A%20%20%20%20%3CRoomGroup%3E%0A%20%20%20%20%20%20%20%20%3CRoom%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CnumberOfAdults%3E2%3C%2FnumberOfAdults%3E%0A%20%20%20%20%20%20%20%20%3C%2FRoom%3E%0A%20%20%20%20%3C%2FRoomGroup%3E%0A%3C%2FHotelRoomAvailabilityRequest%3E";
string xmlpath = url;

// Create a request using a URL that can receive a post. 
WebRequest request = WebRequest.Create(xmlpath);

// Set the Method property of the request to POST.
request.Method = "POST";

// Create POST data and convert it to a byte array.
string postData = xmlpath;
byte[] byteArray = Encoding.UTF8.GetBytes(postData);

// Set the ContentType property of the WebRequest.
request.ContentType = "application/json";

// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;

// Get the request stream.
Stream dataStream = request.GetRequestStream();

// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);

// Close the Stream object.
dataStream.Close();

// Get the response.
WebResponse response = request.GetResponse();

Your server requires a GET not POST .您的服务器需要GET而不是POST Below code works下面的代码有效

 var url = "https://book.api.ean.com/ean-services/rs/hotel/v3/avail?cid=55505&minorRev=30&apiKey=bsm4nqpcawnppkpwjkej2rfq&locale=en_US&currencyCode=INR&xml=%3CHotelRoomAvailabilityRequest%3E%0A%20%20%20%20%3ChotelId%3E106347%3C%2FhotelId%3E%0A%20%20%20%20%3CarrivalDate%3E9%2F29%2F2015%3C%2FarrivalDate%3E%0A%20%20%20%20%3CdepartureDate%3E10%2F1%2F2015%3C%2FdepartureDate%3E%0A%20%20%20%20%3CincludeDetails%3Etrue%3C%2FincludeDetails%3E%0A%20%20%20%20%3CRoomGroup%3E%0A%20%20%20%20%20%20%20%20%3CRoom%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CnumberOfAdults%3E2%3C%2FnumberOfAdults%3E%0A%20%20%20%20%20%20%20%20%3C%2FRoom%3E%0A%20%20%20%20%3C%2FRoomGroup%3E%0A%3C%2FHotelRoomAvailabilityRequest%3E";

using (var wc = new WebClient())
{
    wc.Headers.Add("Accept", "application/xml");
    var str = wc.DownloadString(url);
}

if you want the result as json instead of xml, just comment out the line如果您希望结果为 json 而不是 xml,只需注释掉该行

wc.Headers.Add("Accept", "application/xml");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 远程服务器返回错误:(405)允许方法 - The remote server returned an error: (405) Method Allowed 远程服务器返回错误:(405)方法不允许 - The remote server returned an error: (405) Method Not Allowed 远程服务器返回错误:“(405) Method Not Allowed” - The remote server returned an error: "(405) Method Not Allowed" 调用web api发布方法错误“远程服务器返回错误:(405)不允许使用方法” - calling web api Post method error “The remote server returned an error: (405) Method Not Allowed” Azure移动服务,远程服务器返回错误:(405)不允许的方法 - Azure mobile service, The remote server returned an error: (405) Method Not Allowed 远程服务器返回错误:(405)mvc 5中不允许使用方法 - The remote server returned an error: (405) Method Not Allowed in mvc 5 .NET,远程服务器返回错误:(405) Method Not Allowed - .NET , The remote server returned an error: (405) Method Not Allowed 交换Web服务错误-远程服务器返回不允许的错误405方法 - exchange web service error - the remote server returned an error 405 method not allowed WCF-远程服务器返回了意外的响应:(405)不允许的方法 - WCF - The remote server returned an unexpected response: (405) Method Not Allowed 远程服务器返回意外响应:(405)方法不允许 - The remote server returned an unexpected response: (405) Method Not Allowed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM