我正在跟进这个例子 https://learn.microsoft.com/en-us/azure/azure-functions/functions-test-a-function在 Azure 函数中创建 javascript 函数并使用 postman 发送请求正文时。在 Azure 函数中,可以使用 json 格式的请求正文来测试函数。是否可以将正文作为 xml 而不是 json 发送?使用的请求主体是
{
"name" : "Wes testing with Postman",
"address" : "Seattle, WA 98101"
}
JS HttpTrigger不支持请求体xml反序列化。它以纯 xml 的方式运行。但您可以将 C# HttpTrigger 与 POCO 对象一起使用:
函数.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);
}
请求头:
Content-Type: text/xml
请求正文:
<RequestData xmlns="http://functions">
<Id>name test</Id>
<Value>value test</Value>
</RequestData>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)