JS HttpTrigger ne prend pas en charge la désérialisation du corps xml de la demande. Il vient pour fonctionner comme xml simple. Mais vous pouvez utiliser C# HttpTrigger avec l'objet POCO:
function.json:
{
"bindings": [
{
"type": "httpTrigger",
"name": "data",
"direction": "in",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"name": "res",
"direction": "out"
}
]
}
run.csx
#r "System.Runtime.Serialization"
using System.Net;
using System.Runtime.Serialization;
// DataContract attributes exist to demonstrate that
// XML payloads are also supported
[DataContract(Name = "RequestData", Namespace = "http://functions")]
public class RequestData
{
[DataMember]
public string Id { get; set; }
[DataMember]
public string Value { get; set; }
}
public static HttpResponseMessage Run(RequestData data, HttpRequestMessage req, ExecutionContext context, TraceWriter log)
{
log.Info($"C# HTTP trigger function processed a request. {req.RequestUri}");
log.Info($"InvocationId: {context.InvocationId}");
log.Info($"InvocationId: {data.Id}");
log.Info($"InvocationId: {data.Value}");
return new HttpResponseMessage(HttpStatusCode.OK);
}
tête de demande:
Content-Type: text/xml
Demande corps:
<RequestData xmlns="http://functions">
<Id>name test</Id>
<Value>value test</Value>
</RequestData>
Je n'ai pas utilisé cette approche puisque je n'utilise pas C#. J'ai fini par passer le corps au JS HttpTrigger comme un fichier xml pur et ensuite converti le xml en littéral d'objet JS en utilisant le paquet de noeud [xml2js] (https://www.npmjs.com/package/xml2js) – LeadingMoominExpert