Skip to content
This repository was archived by the owner on Aug 14, 2026. It is now read-only.
This repository was archived by the owner on Aug 14, 2026. It is now read-only.

HttpRequestMessage does not have data in ASP.NET Core #34

Open

Description

@huyjack178

Currently I am converting LINE with bot framework application to ASP.NET Core, implement the same controller
[HttpPost] public async Task<ActionResult> Post([FromBody] HttpRequestMessage request)

But when I test webhook, HttpRequestMessage does not have any data. Can anyone help?

Activity

  1. kenakamu commented on Jan 22, 2019

    @kenakamu
    Contributor
  2. seanmars commented on Jan 22, 2019

    @seanmars

    I got same issue, but i rewrite the WebhookRequestMessageHelper by using HttpContext.
    Some sample to get the content:

    using(var reader = new StreamReader(httpContext.Request.Body))
    {
        var content = await reader.ReadToEndAsync();
        ...
        ...
        dynamic json = JsonConvert.DeserializeObject(content);
    }
  3. fuyunekojima commented on Apr 25, 2020

    @fuyunekojima

    Using seanmars' code to create a method like the one below, I was able to create an HttpRequestMessage that the "GetWebhookEventsAsync" extension method can use successfully.

    Note that the "X-Line Signature" key must be included in the header.

    private async Task<HttpRequestMessage> GetLineRequest()
    {
        using (var reader = new StreamReader(HttpContext.Request.Body))
        {
            var content = await reader.ReadToEndAsync();
            var reqMessage = new HttpRequestMessage
            {
                RequestUri = new Uri("https://localhost:5001/callback"),
                Content = new StringContent(content, Encoding.UTF8, "application/json")
            };
            var signature = HttpContext.Request.Headers.Where(x => x.Key == "X-Line-Signature").First();
            reqMessage.Headers.Add(signature.Key, signature.Value.ToString());
            return reqMessage;
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions