Can Azure functions return XML?

We are looking for Node.js an example of XML return from Azure Function. The code that I have below returns an xml string, but the Content-Type response is set to text / plain; charset = utf-8 instead of text / xml; encoding = UTF-8

index.js

module.exports = function(context, req) {
    var xml = '<?xml version="1.0" encoding="UTF-8"?><Response><Say>Azure functions!</Say></Response>';

    context.res = {
        contentType: 'text/xml',
        body: xml
    };

    context.done();
};

Here are the bindings.

function.json

{
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req"
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ],
  "disabled": false
}
+4
source share
2 answers

Mark

Absolutely! You were close, but you can see an example of how you can set the type of content in the answer here .

, , .

+6

Fabio , :

module.exports = function(context, req) {
    var xml = '<?xml version="1.0" encoding="UTF-8"?><Response><Say>Azure functions!</Say></Response>';

    context.res = {
        "headers" : { 
            "Content-Type" : 'text/xml'
        },
        "body": xml,
        "isRaw" : true
    };

    context.done();
};

.json.

"" , . , , CORS, , -, -, CORS. CORS , CORS .

"isRaw", true, Azure , XML .

FYI, , . , , ; / Github.

+3

Source: https://habr.com/ru/post/1660453/


All Articles