gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:02:30 25 4
gpt4 key购买 nike

我正在尝试从 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>"

如何去掉引号?

最佳答案

您可以使用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"};

关于c# - Azure 函数如何返回 XML 而不是字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72111716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com