Azure函数如何返回XML而不是字符串

6ovsh4lw  于 2022-12-14  发布在  其他
关注(0)|答案(1)|浏览(122)

我正在尝试从Azure函数返回XML配置文件。配置正在写入如下所示的字符串。

xml = @"<note>
                        <to>Tove</to>
                        <from>Jani</from>
                        <heading>Reminder</heading>
                        <body>Don't forget me this weekend!</body>
                        </note>";

那我就这样退回去

return req.CreateResponse(HttpStatusCode.OK, xml.Replace("\r\n",""));

但是,HTTP调用的结果如下所示

"
    <note>
        <to>Tove</to>
        <from>Jani</from>
        <heading>Reminder</heading>
        <body>Don't forget me this weekend!</body>
</note>"

如何去掉括起来的引号?

lsmepo6l

lsmepo6l1#

您可以使用https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.contentresult?view=aspnetcore-6.0

var xml = @"<note>
                        <to>Tove</to>
                        <from>Jani</from>
                        <heading>Reminder</heading>
                        <body>Don't forget me this weekend!</body>
                        </note>";
 return new ContentResult() { Content = xml, ContentType = "text/xml"};

相关问题