目前,我使用的是Outlook API,即使是艰难的工作,我通常也使用通过Nuget获取的Outlook库。我已经无法接受活动邀请了。因此,我对Outlook API进行了轻松的调用。但是,当我拨打电话时,我收到以下消息{“错误”:{“代码”:“ InvalidMethod”,“消息”:“动作只能作为'POST'请求调用。”}}执行通话。
错误代码
class Program
{
static void Main(string[] args)
{
var testAccept = ExecuteClientCall.AcceptEvent().Result;
}
public static async Task<bool> AcceptEvent()
{
AuthenticationContext authenticationContext = new AuthenticationContext(CrmPrototype.Helpers.AuthHelper.devTenant);
try
{
var token = await GetTokenHelperAsync(authenticationContext, CrmPrototype.Helpers.AuthHelper.OutlookAuthenticationEndpoint);
string requestUrl = "https://outlook.office.com/api/v2.0/Users/***@nowwhere.com/events('AAQkAGZiNDQxZTVkLWQzZjEtNDdjNy04OTc4LTM4NmNjM2JiOTRjNAAQAFpV0CnWR0FIpWFYRtszPHU=')/accept";
HttpClient hc = new HttpClient();
hc.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
var method = new HttpMethod("POST");
var request = new HttpRequestMessage(method, requestUrl)
{
Content = new StringContent("{SendResponse: true}", Encoding.UTF8, "application/json")
};
HttpResponseMessage hrm = await hc.GetAsync(requestUrl);
if (hrm.IsSuccessStatusCode)
{
string jsonresult = await hrm.Content.ReadAsStringAsync();
var stophere = 0;
}
else
{
return false;
}
return true;
}
catch (Exception ex)
{
throw;
}
}
}
也许是因为你打电话
hc.GetAsync(requestUrl);
医生说这种方法:
Sends a GET request to the specified Uri as an asynchronous operation.
尝试:
PostAsync(Uri, HttpContent)
https://msdn.microsoft.com/zh-CN/library/system.net.http.httpclient(v=vs.118).aspx
希望这对您有所帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句