Last post Sep 22, 2019 08:14 AM by mywatermelon
Member
53 Points
245 Posts
Sep 21, 2019 06:33 AM|mywatermelon|LINK
Hi, now I need to get the body from a post. Here is the code:
public string GetMsg([FromBody]xml x) { return ""; } public class xml { public string ToUserName { get; set; } public string FromUserName { get; set; } public string CreateTime { get; set; } public string MsgType { get; set; } public string Content { get; set; } public string MsgId { get; set; } }
These codes work well.
However, the remote server will post several XML to my server with the same parent node but different child nodes for different functions.
For example:
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1348831860</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[this is a test]]></Content> <MsgId>1234567890123456</MsgId> </xml>
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1357290913</CreateTime> <MsgType><![CDATA[voice]]></MsgType> <MediaId><![CDATA[media_id]]></MediaId> <Format><![CDATA[Format]]></Format> <MsgId>1234567890123456</MsgId> </xml>
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1357290913</CreateTime> <MsgType><![CDATA[video]]></MsgType> <MediaId><![CDATA[media_id]]></MediaId> <ThumbMediaId><![CDATA[thumb_media_id]]></ThumbMediaId> <MsgId>1234567890123456</MsgId> </xml>
I can only define one 'xml' class in a cs file, now it seems I have to create many cs file and define the 'xml' class in each of them.
It is so troublesome. And also, I can change the code of the remote server.
How can I deal with this? Thank you.
All-Star
57864 Points
15491 Posts
Sep 21, 2019 03:27 PM|bruce (sqlwork.com)|LINK
Sep 22, 2019 08:14 AM|mywatermelon|LINK
Thank you. By using the [XmlRoot("xml")] ,it works.
Member
53 Points
245 Posts
How can I get body from a post with the same parent node but different child node?
Sep 21, 2019 06:33 AM|mywatermelon|LINK
Hi, now I need to get the body from a post. Here is the code:
These codes work well.
However, the remote server will post several XML to my server with the same parent node but different child nodes for different functions.
For example:
I can only define one 'xml' class in a cs file, now it seems I have to create many cs file and define the 'xml' class in each of them.
It is so troublesome. And also, I can change the code of the remote server.
How can I deal with this? Thank you.
All-Star
57864 Points
15491 Posts
Re: How can I get body from a post with the same parent node but different child node?
Sep 21, 2019 03:27 PM|bruce (sqlwork.com)|LINK
Member
53 Points
245 Posts
Re: How can I get body from a post with the same parent node but different child node?
Sep 22, 2019 08:14 AM|mywatermelon|LINK
Thank you. By using the [XmlRoot("xml")] ,it works.