Ali Alzahrani
Ali Alzahrani

Reputation: 529

Method Not Allowed using Cisco REST API

I am trying to change agent state using REST API provided from Cisco. here is the code that I wrote :

ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("https://url:8445/finesse/api/User/agent2"));
request.Credentials = new NetworkCredential("agent2", "12345");

request.Method = "POST";
request.ContentType = "application/xml";
// request.Accept = "application/xml";
XElement redmineRequestXML =
new XElement("User",
new XElement("state", "READY"),
new XElement("extension", "3010")
);
byte[] bytes = Encoding.UTF8.GetBytes(redmineRequestXML.ToString());
request.ContentLength = bytes.Length;

using (Stream putStream = request.GetRequestStream())
{
putStream.Write(bytes, 0, bytes.Length);
}
// Log the response from Redmine RESTful service
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
MessageBox.Show(reader.ReadToEnd());
}

And I am getting this error :

The remote server returned an error: (405) Method Not Allowed.

so please any idea could help solving this issue ?

Upvotes: 1

Views: 1226

Answers (1)

Ali Alzahrani
Ali Alzahrani

Reputation: 529

after 2 days I figured out that the issue is to replace this line :

request.Method = "POST";

by this line :

request.Method = "PUT";

Upvotes: 1

Related Questions