Home > Software design >  How to send ASCII codes stream from an ASP.NET MVC controller
How to send ASCII codes stream from an ASP.NET MVC controller

Time:10-01

I developed an ASP.NET MVC application in C# that sends some commands to a device (for the case, it does not matter what device is).

From a controller, I am using this code to return the "OK" response:

public async Task<ActionResult> GetRequest(string SN, string INFO)
{
    string response = "OK";
        
    return Content(response), "text/plain");
}

When I analyze the HTTP protocol using Wireshark, I see this:

enter image description here

That looks OK, however, when I see the same, but using a supplier's web application (developed in Java), the same OK is returned, but it is seen in a different way. Maybe they are sending a bytes stream.

enter image description here

Notice that Wireshark shows a data stream 4F 4B. Which are ASCII codes of "OK".

Am I right that the other application is returning the "OK" word as a byte stream? To get the same in my ASP.NET MVC application, should I use FileResult?

Thanks Jaime

CodePudding user response:

Http client's are generally very forgiving of invalid header values. Content-Encoding: UTF-8 isn't a supported value. This header is supposed to indicate if the payload has been compressed. And which compression method has been used.

Since the header is present, Wireshark logs how it tries to decompress the payload. But can't because it isn't actually compressed. So it just displays the raw bytes in hexadecimal, since that is ultimately what Wireshark is for.

  • Related