Search code examples
c#.netresthttpresponsehttp-put

Content type in HTTP call


My HTTP Put call response is printed by the following code.

HttpResponseMessage response = await client.PutAsync("https://restapi.surveygizmo.com/v4/survey/2692209/surveypage/3/surveyquestion?", inputMessage.Content);

string returnString = response.ToString();
Console.WriteLine(returnString);
Console.WriteLine(response.StatusCode);

I want to print the content type information to be printed on console or some other format. Basically i want to see the content type in c#. How do i do that?


Solution

  • By using HttpContent and read the buffer.

    A base class representing an HTTP entity body and content headers.

    using (HttpContent content = response.Content)
    {
        // ... Read the string.
        string result = await content.ReadAsStringAsync();
    
        // ... Display the result.
        Console.WriteLine(result);
    }