远程服务器返回错误 405 方法不允许
本文关键字:方法 不允许 错误 返回 服务器 | 更新日期: 2023-09-27 18:34:22
>我正在尝试将邮件从收件箱移动到已删除的文件夹。但是当我运行该程序时,我收到上述错误消息。请帮助解决这个问题。这是我的代码
string mailboxURI = "URL//";
string username = "username";
string password = "Password";
string domain = "domain name";
Console.WriteLine("Connecting to Exchange Server....");
try
{
NetworkCredential credential = new NetworkCredential(username, password, domain);
ExchangeClient client = new ExchangeClient(mailboxURI, credential);
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();
// List all messages from Inbox folder
Console.WriteLine("Listing all messages from Inbox....");
ExchangeMessageInfoCollection msgInfoColl = client.ListMessages(mailboxInfo.InboxUri);
foreach (ExchangeMessageInfo msgInfo in msgInfoColl)
{
// Move message to "Deleted" folder, after processing certain messages
// based on some criteria
if (msgInfo.Date != DateTime.Today)
{
// Move it
client.MoveItems(msgInfo.UniqueUri, client.MailboxInfo.RootUri + "/Deleted/" + msgInfo.Subject);
Console.WriteLine("Message moved...." + msgInfo.Subject);
}
else
{
Console.WriteLine("Not moved:" + msgInfo.Subject);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error:"+ex.Message);
Console.Read();
}
}
当服务器除外,服务器上的方法与您的 http 请求类型不匹配时,会出现此错误。
例如,服务器期待http GET方法,但是您的代码正在使用POST方法与服务器通信,反之亦然。
您可能希望更改代码中的方法类型。
干杯阿南特