简体   繁体   English

从我的Web服务中读取Http POST正文内容? (.net 3.5)

[英]Reading the Http POST body content from my web service? (.net 3.5)

Okay, this is driving me nuts. 好的,这让我疯了。 I'm integrating Amazon SNS into a web service I have. 我正在将Amazon SNS集成到我拥有的Web服务中。 Amazon simply sends an HTTP post with a bunch of json content to the url I specify. 亚马逊只是将带有一堆json内容的HTTP帖子发送到我指定的URL。 I just can't access it. 我只是无法访问它。

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void HandleBounce()
{
    notification = //I need to put the JSON content into here
}

Amazon simply access the url ( http://test.com/webservice.aspx/HandleBounce ). 亚马逊只需访问网址( http://test.com/webservice.aspx/HandleBounce )。 The method is being called correctly. 正确调用该方法。 I just need to get the data it's sending in the post. 我只需要在帖子中获取它发送的数据。 How do I do that? 我怎么做?

EDIT: 编辑:

I originally tried using 我最初尝试使用

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void HandleBounce(string json)
{
    notification = //I need to put the JSON content into here
}

but when I do this, the method is simply never called at all. 但是当我这样做时,根本就不会调用该方法。 At least when I remove the parameter, the method is working. 至少当我删除参数时,该方法正在运行。

EDIT 2: 编辑2:

This is from the amazon website as to what request they send to me: 这是来自亚马逊网站,他们发送给我的请求是:

POST / HTTP/1.1
x-amz-sns-message-type: SubscriptionConfirmation
x-amz-sns-message-id: 165545c9-2a5c-472c-8df2-7ff2be2b3b1b
x-amz-sns-topic-arn: arn:aws:sns:us-west-2:123456789012:MyTopic
Content-Length: 1336
Content-Type: text/plain; charset=UTF-8
Host: example.com
Connection: Keep-Alive
User-Agent: Amazon Simple Notification Service Agent

{
  "Type" : "SubscriptionConfirmation",
  "MessageId" : "165545c9-2a5c-472c-8df2-7ff2be2b3b1b",
  "Token" : "2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582afbacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736",
  "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
  "Message" : "You have chosen to subscribe to the topic arn:aws:sns:us-west-2:123456789012:MyTopic.\nTo confirm the subscription, visit the SubscribeURL included in this message.",
  "SubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-west-2:123456789012:MyTopic&Token=2336412f37fb687f5d51e6e241d09c805a5a57b30d712f794cc5f6a988666d92768dd60a747ba6f3beb71854e285d6ad02428b09ceece29417f1f02d609c582afbacc99c583a916b9981dd2728f4ae6fdb82efd087cc3b7849e05798d2d2785c03b0879594eeac82c01f235d0e717736",
  "Timestamp" : "2012-04-26T20:45:04.751Z",
  "SignatureVersion" : "1",
  "Signature" : "EXAMPLEpH+DcEwjAPg8O9mY8dReBSwksfg2S7WKQcikcNKWLQjwu6A4VbeS0QHVCkhRS7fUQvi2egU3N858fiTDN6bkkOxYDVrY0Ad8L10Hs3zH81mtnPk5uvvolIC1CXGu43obcgFxeL3khZl8IKvO61GWB6jI9b5+gLPoBc1Q=",
  "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem"
  }

Using the following adjustments, I was able to resolve the issue: 使用以下调整,我能够解决问题:

    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public void HandleBounce() //This method is called from Amazon Simple Notification Service when we receive a bounce.
    {
        string notification = "";
        using (var stream = new MemoryStream())
        {
            var request = HttpContext.Current.Request;
            request.InputStream.Seek(0, SeekOrigin.Begin);
            request.InputStream.CopyTo(stream);
            notification = Encoding.UTF8.GetString(stream.ToArray());
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 ASP.NET Web API ValueProvider 中的 HTTP POST 请求检索正文值? - How do I retrieve body values from an HTTP POST request in an ASP.NET Web API ValueProvider? 如何从.NET 3.5 WebClient或WebRequest将对象发布到Web API - How to POST an Object to Web API from .NET 3.5 WebClient or WebRequest 为什么我的HTTP POST正文内容被接收/处理为NULL? - Why is my HTTP POST Body content received/processed as NULL? 无法从.NET 3.5应用程序使用Web Api服务 - Unable to consume Web Api Service from .NET 3.5 application 在我的Web API端点中解析HTTP POST请求正文时出错 - Error parsing HTTP POST request body in my web api endpoint 如何创建具有 http post 功能的 Web Api,该功能可以从正文中获取任何动态 json 内容并能够将其解析为字符串 - How to create a web Api have http post function which can take any dynamic json content from body and able to parse it into string Call.Net 3.5 WCF 服务来自.Net 2.0 标准 ASMX Web 服务客户端 - Call .Net 3.5 WCF service from .Net 2.0 Standard ASMX Web Service Client 序列化ASP.NET Web服务HTTP POST请求结果 - Serialize ASP.NET Web Service HTTP POST request results 在Web引用.net 3.5中更新服务引用 - Updating Service reference in web reference .net 3.5 ASP.NET Web API无法从POST正文读取 - ASP.NET Web API unable to read from POST body
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM