我試圖更新電子郵件類別,並在Outlook 365 API
和HttpClient
的幫助下將其標記爲已讀。關注this tutorial。使用Office 365 API和HttpClient在C#中更新電子郵件類別時出現錯誤請求錯誤
在教程中,代碼如下更新類別並標記爲已讀,但是,我不明白我應如何將這些詳細信息附加到HttpClient
和請求中。
PATCH https://outlook.office.com/api/v2.0/me/messages/AAMkAGE0Mz8S-AAA=
Content-Type: application/json
{
"Categories": [
"Orange category",
"Green category"
],
"IsRead": true
}
的方法和HttpClient的我使用情況如下:
更新1
public string UpdateCategory(AuthenticationResult result, string mediator)
{
//HTTPMethod.PATCH not available to adding it manualy.
var httpMethod = new HttpMethod("PATCH");
HttpRequestMessage request = new HttpRequestMessage(httpMethod, mediator);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
//JSON in a string variable for test
var tempJson = @"{""Categories"" : ""Checking""}";
Converting string to JSON
var jsonData = JsonConvert.SerializeObject(tempJson);
//Adding the JSON to request.Content
request.Content =new StringContent(jsonData,Encoding.UTF8, "application/json");
HttpResponseMessage response = httpClient.SendAsync(request).Result;
if (!response.IsSuccessStatusCode)
throw new WebException(response.StatusCode.ToString() + ": " + response.ReasonPhrase);
mediator = response.Content.ReadAsStringAsync().Result;
return mediator;
}
它拋出Bad Request
錯誤。
我正在使用365 API與WPF應用程序。請指教。