According to the test, req.Query
obtains parameters in the form of <your-url>? parameter1 = value1¶meter2 = value2
. In other words, req.Query
can only get the parameters in the Get
request.
You are sending a post request, so using req.Query
cannot get the parameters you want.
I think it has something to do with the last line of code. data.name. I don't understand what that line is doing.
This code is to judge whether the name is empty, if it is empty, then name=data?name.
req.Query
did not get the value of name, so this code gets the value of name from data?.name
, so this is the reason why name
has a value but attachmentName
has no value in your result .
The correct code should look like this:
public static class Function1
{
[FunctionName("Function1")]
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 attachmentName = req.Query["attachmentName"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
attachmentName = attachmentName ?? data?.attachmentName;
log.LogInformation(name);
log.LogInformation(attachmentName);
return new OkObjectResult(name);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…