且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过http Post请求将XML发送到Web Api的问题

更新时间:2023-02-03 15:14:20

最终解决方案是将Post参数类型更改为XElement:

Final solution was to change the Post param type to XElement:

[Route("api/razorXmlRequest")]
public class RazorXmlRequestController : ApiController
{
    /// <summary>
    /// Raw Razor request XML 
    /// </summary>
    /// <returns>Razor reply message as text</returns>
    [HttpPost]
    public async Task<HttpResponseMessage> Post([FromBody]XElement xml)
    {
        HttpResponseMessage resp = new HttpResponseMessage(HttpStatusCode.OK);
        RazorSession cred = RzWebApi.Cred;
        string reply = await RzWebApi.RazorSrv.xmlRequests.Request(cred, xml);
        resp.Content = new StringContent(reply, System.Text.Encoding.UTF8, "application/xml");
        return resp;
    }
}

此方法直接工作,甚至没有提供以上先生们建议的XmlFormatter(@TusharJ,无论如何,谢谢您的输入).

This worked straight-away without even providing the XmlFormatter as the gentlemen had suggested above (@TusharJ, thank you anyway for your input).