不允许使用 Cisco REST 的方法 API
Method Not Allowed using Cisco REST API
我正在尝试使用 Cisco 提供的 REST API 更改代理状态。
这是我写的代码:
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());
}
我收到这个错误:
The remote server returned an error: (405) Method Not Allowed.
请问有什么想法可以帮助解决这个问题吗?
2 天后,我发现问题是替换此行:
request.Method = "POST";
通过这一行:
request.Method = "PUT";
我正在尝试使用 Cisco 提供的 REST API 更改代理状态。 这是我写的代码:
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());
}
我收到这个错误:
The remote server returned an error: (405) Method Not Allowed.
请问有什么想法可以帮助解决这个问题吗?
2 天后,我发现问题是替换此行:
request.Method = "POST";
通过这一行:
request.Method = "PUT";