[英]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.