我有Visual Studio 2017 15.3并安装了Azure开发工作负载。调试Http触发器Azure功能VS 2017
我根据本文创建一个空白HttpTrigger
:
我可以调试成功,如果我用Name
作为参数查询字符串。
不过,如果我使用邮差来创建此POST请求:
{
"name": "Azure"
}
我收到以下错误:
"mscorlib: Exception while executing function: HttpTrigger . Anonymously Hosted DynamicMethods Assembly: 'Newtonsoft.Json.Linq.JObject' doe s not contain a definition for 'name'."
这是我在Visual Studio 2017的功能应用代码:
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
namespace VS2017TestFunctionApp
{
public static class HttpTrigger
{
[FunctionName("HttpTrigger")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
// Set name to query string or body data
name = name ?? data?.name;
return name == null
? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
: req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}
}
}
另外,如果我在Run函数中复制完全相同的代码并在af中使用相同的测试帖子通过Azure门户联合应用程序,它一切正常。
如果你移动到下一行,从你的破发点,以“名”你应该得到的错误。 – Stanza
另外,如果我在Run函数中复制完全相同的代码,并通过Azure门户在函数应用程序中使用相同的测试帖子,则一切正常。 – Stanza
''如果你从中断点移动到'name'的下一行,你应该得到这个错误。''我没有得到错误,代码工作正常。 –