ASP.Net API Access to HttpRequestMessage

I have an ASP.Net 4.5 application that I am trying to upgrade to ASP.Net Core. This application receives calls from a third-party application.

In my old application, I have an action that looks like this:

public async Task<HttpResponseMessage> RealTimeAsync(HttpRequestMessage request)
{
    var StatusMessage = string.Empty;
    try
    {
        var doc = new XmlDocument();
        doc.Load(await request.Content.ReadAsStreamAsync());

From 4.5 this works great. However, when I use this code in the ASP.Net core, I get the error "The object reference is not set to an object instance" because request.Content is null.

Requests for two applications (4.5 and .Net Core) are the same. Why is request.Content null in my .Net Core application?

When I referenced this post: ASP.NET Core HTTPRequestMessage returns a strange JSON message

I tried installing the proposed Nuget package. However, it is not compatible with .Net Core:

: Microsoft.AspNet.WebApi.Client 5.2.2 netcoreapp1.0 (.NETCoreApp, Version = v1.0). Microsoft.AspNet.WebApi.Client 5.2.2 : : - net45 (.NETFramework, Version = v4.5): - -net45 + netcore45 + 8 + wp81 + wpa81 (.NETPortable, Version = v0.0, = 8 + netcore45 + net45 + wp81 + wpa81) : .NETCoreApp, Version = 1.0.

+4
1

, .

public Task<IActionResult> RealTimeAsync() {
    var StatusMessage = string.Empty;
    try {
        var request = this.Request;
        var doc = new XmlDocument();
        doc.Load(request.Body); //request.Body returns a stream
    //...other code...
+4

Source: https://habr.com/ru/post/1671263/


All Articles