c# - HTTP 触发 azure 函数在本地不运行时出现问题
问题描述
我在 Visual Studio (C#) 中有一个基本的 HTTP 触发 azure 函数:
[FunctionName("HttpTriggerCSharp")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "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");
}
但我有两个问题:
(1) 我只希望它接收“发布”请求。但是当我从参数中取出时,"get"
该函数不再接收我在 Azure 中的请求。我得到一个404 Not Found
. 但在本地它仍然收到我的请求并且工作正常。
(2) 此外,Azure 中未收到请求正文。它是空的。再次在本地运行时不会出现此类问题。
我发现了几个人遇到问题的案例(2),但还没有找到解决方法。关于问题(1),目前还没有网上发布过类似的案例。
有谁知道为什么会这样?
解决方案
推荐阅读
- python-3.x - 微调的 VGG-16 对所有测试图像给出完全相同的预测
- node.js - Google Cloud Function/NodeJS - 从 JSON 表单事件解析 int
- java - 带有 MySQL 的 JPA 返回错误的最后插入 id
- python - 熊猫将一帧中的值分配给选定行中另一帧中的对应列
- c - 无法在 C 中输出预期的 **argv
- javascript - TypeError:props.handleToggle 不是函数
- c - 意外的 getc(stdin) 在 EOF 之前等待读取文件的最后一个字符
- vue.js - Vuex 与简单共享数据
- c - 使用 c 查找斐波那契中的第 n 个数字
- bash - 无法从终端删除文件