0

I use var content = Request.Content.ReadAsStringAsync().Result; to get that data posted to mine is

<xml><OpenId><![CDATA[oX2XXXXXX-HFCR8O_BkI]]></OpenId>
<AppId><![CDATA[wxbcXXXXXX4d]]></AppId>
<IsSubscribe>0</IsSubscribe>
<ProductId><![CDATA[XXXXXX01]]></ProductId>
<TimeStamp>1416482878</TimeStamp>
<NonceStr><![CDATA[XXXXXXX]]></NonceStr>
<AppSignature><![CDATA[cff4XXXXXX8a513891f0]]></AppSignature>
<SignMethod><![CDATA[sha1]]></SignMethod>
</xml>

And I've crated the structure

public class PackageModal
    {
        public string OpenId { get; set; }
        public string AppId { get; set; }
        public string IsSubscribe { get; set; }
        public string ProductId { get; set; }
        public string TimeStamp { get; set; }
        public string NonceStr { get; set; }
        public string AppSignature { get; set; }
        public string SignMethod { get; set; }
    }

But in the controller, [HttpPost]

public string PostNotify(PackageModal modal)
{
 ....
}

Why the modal is null? Do I need to specify that posted data is XML-format?

2

2 Answers 2

0

What about if you sent a JSON instead of XML, will that work ?

if not, try use [FromBody] in your method, so something like

public string PostNotify([FromBody]PackageModal modal)
{
 ....
}

This will tell the model binder to try map the PackageModel from the request body.

Hope that helps.

Sign up to request clarification or add additional context in comments.

2 Comments

[FromBody] Not working. The api is a payment notify url. I can't decide to receive other than the xml format data.
Yeah, but how will you client send the xml.? As a query string (in the url) or in the message body?
0
[HttpPost]
public string ReturnXmlDocument(HttpRequestMessage request)
{
    var doc = new XmlDocument();
    doc.Load(request.Content.ReadAsStreamAsync().Result);
    return doc.DocumentElement.OuterXml;
}

That's it!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.