在.net Core 1.0中解析AWS SNS通知

编程入门 行业动态 更新时间:2024-10-12 18:19:06
本文介绍了在 Core 1.0中解析AWS SNS通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个VisualStudio17无服务器应用程序项目,并且正在使用核心Web Api。

I have a VisualStudio17 serverless application project and am using core Web Api.

我想确认我的SNS订阅,但是我遇到一个问题,即AWS发送标头 content-type 设置为文本/纯文本; charset = UTF-8 而body为JSON。

I want to confirm my SNS subscription, but I have a problem that AWS sends the POST request with header content-type set to text/plain; charset=UTF-8 while body is JSON.

以下是他们的文档:

POST / HTTP/1.1 x-amz-sns-message-type: Notification x-amz-sns-message-id: da41e39f-ea4d-435a-b922-c6aae3915ebe x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic x-amz-sns-subscription-arn: arn:aws:sns:us-west-2:123456789012:MyTopic:2bcfbf39-05c3-41de-beaa-fcfcc21c8f55 Content-Length: 761 Content-Type: text/plain; charset=UTF-8 Host: ec2-50-17-44-49pute-1.amazonaws Connection: Keep-Alive User-Agent: Amazon Simple Notification Service Agent { "Type" : "Notification", "MessageId" : "da41e39f-ea4d-435a-b922-c6aae3915ebe", "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic", "Subject" : "test", "Message" : "test message", "Timestamp" : "2012-04-25T21:49:25.719Z", "SignatureVersion" : "1", "Signature" : "EXAMPLElDMXvB8r9R83tGoNn0ecwd5UjllzsvSvbItzfaMpN2nk5HVSw7XnOn/49IkxDKz8YrlH2qJXj2iZB0Zo2O71c4qQk1fMUDi3LGpij7RCW7AW9vYYsSqIKRnFS94ilu7NFhUzLiieYr4BKHpdTmdD6c0esKEYBpabxDSc=", "SigningCertURL" : "sns.us-west-2.amazonaws/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem", "UnsubscribeURL" : "sns.us-west-2.amazonaws/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-west-2:123456789012:MyTopic:2bcfbf39-05c3-41de-beaa-fcfcc21c8f55" }

内容类型:文本,正文JSON。这使得解析非常困难,并且简单的

Content-type: text, body JSON. This makes it parsing quite difficult, and a simple

public void Post([FromBody] string t)//或动态t / code>

public void Post([FromBody] string t) // or dynamic t for the matter

不起作用并抛出请求在操作筛选器'Microsoft.AspNetCore.Mvc.ModelBinding中短路。 异常。

我错过了什么吗?他们为什么这样做,我该如何处理?

Am I missing something? Why are they doing this and how do I work with this?

推荐答案

我按照此答案,方法是将 text / plain 添加到 JsonInputFormatter 应该格式化的格式。

I made it work like I described in this answer, by adding text/plain to formats that JsonInputFormatter should format.

public void ConfigureServices(IServiceCollection services) { services.AddMvc(config => { foreach (var formatter in config.InputFormatters) { if (formatter.GetType() == typeof(JsonInputFormatter)) ((JsonInputFormatter)formatter).SupportedMediaTypes.Add( MediaTypeHeaderValue.Parse("text/plain")); } }); ... }

更多推荐

在.net Core 1.0中解析AWS SNS通知

本文发布于:2023-11-06 08:24:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563183.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通知   Core   net   SNS   AWS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!