For .Net Core, the
What is the equivalent of GetQueryNameValuePairs when using .Net Core 2.x?
// parse query parameter
string name = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
.Value;
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@7100SW Thanks for the feedback! We are currently investigating and will update you shortly.
@7100SW Sorry about the outdated samples. We are in the process of updating the docs for Functions v2.
In the meantime, you can change req to type Microsoft.AspNetCore.Http.HttpRequest instead of System.Net.Http.HttpRequestMessage and get query params like this
string name = req.Query["name"];
We will keep this issue open for tracking the update of this specific doc.
@7100SW I hope my previous comment answers your query. To be thorough, here is a complete sample for V2
[FunctionName("MyHttpTrigger")]
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");
}
We have assigned the issue to the content author to review and update the samples in this doc
One of the limiting factors with moving to HttpRequest is that it can't be used to generate the status responses from a durable function orchestration. This can be solved by using the compatability shim in Microsoft.AspNetCore.Mvc.WebApiCompatShim to get an HttpRequestMessage out of an HttpRequest
HttpRequestMessageFeature hreqmf = new HttpRequestMessageFeature(req.HttpContext);
HttpRequestMessage httpRequestMessage = hreqmf.HttpRequestMessage;
return starter.CreateCheckStatusResponse(httpRequestMessage, instanceId);
Thanks, again @7100SW for creating this issue.
We are still working toward a final fix, but for now I need to close this issue. Due to the volume of issues in our queue, our policy is to close issues that have been inactive for the last 90 days.
I will still update this thread once the final change is published to the remaining code samples.
Thanks again!
Most helpful comment
One of the limiting factors with moving to HttpRequest is that it can't be used to generate the status responses from a durable function orchestration. This can be solved by using the compatability shim in
Microsoft.AspNetCore.Mvc.WebApiCompatShimto get an HttpRequestMessage out of an HttpRequest