【发布时间】:2020-06-06 13:18:45
【问题描述】:
我是 Azure 功能的新手。我有这个简单的.net核心代码如下:
public static class HttpExample
{
[FunctionName("HttpExample")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
}
此代码运行良好并返回 Hello, Function。但是,如果我像这样将其更改为“世界”:
string name = req.Query["World"]; //may be I would like to try multiple strings with space? Just to have fun learning.
它返回我:
Please pass a name on the query string or in the request body.
如何使用此函数返回任何特定的字符串?
谢谢。
【问题讨论】:
标签: c# .net-core azure-functions