Tuesday, December 25, 2018

HttpRequest and HttpRequestMessage for Azure Functions

I was working on Microsoft Learn, "Share your location as a text message using Azure Functions and Twilio", and faced a problem on HttpRequest class for Azure Functions. Usually Azure Functions takes HttpRequest class for extracting request. However, the tutorial described HttpRequestMessage. I was really confused because HttpRequestMessage works partly, but it does not support Body property.

For example, this includes HttpRequestMessage but does not support req.Body.


The below works without error.

The difference is HttpRequest and HttpRequestMessage. It looks there are some classes and makes me confused.

1) System.Net.Http.HttpRequestMessage
2) Windows.Web.Http.HttpRequestMessage
3) Microsoft.AspNetCore.Http.HttpRequest
4) System.Web.HttpRequest

We usually use 3) for Azure Functions.