我的C#应用程序中有一个服务,该服务使用App Center的api推送通知。当我在邮递员上使用same详细信息(即content,header auth,owner_name和app_name)时,我的所有请求都返回401(未经授权)。工作成功并发送应用程序。
这非常令人困惑,我想知道邮递员是否处理了我遗漏的一些零碎部分。
private async Task<bool> PostHttpRequest(PushNotificationModel pushNotificationModel)
{
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("X-API-Token", _appCenterApiToken);
var url = "https://api.appcenter.ms/v0.1/apps/myowner/myapp/push/notifications";
var content = JsonConvert.SerializeObject(pushNotificationModel);
var buffer = Encoding.UTF8.GetBytes(content);
var byteContent = new ByteArrayContent(buffer);
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = await _httpClient.PostAsync(url, byteContent);
return response.IsSuccessStatusCode;
}
我调试了此代码,并使用了传递给客户端的相同数据来在Postman上使用,因此,例如为什么不存在Model
数据。
非常感谢您的帮助!
在启动表单中输入以下代码。
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;