Cannot see the value of httpcontent when debugging RRS feed

  • Question

  • I have some code as follows

    string Payload = "{\"case_id\":\"FS-Case-88062659\",\"stage_name\":\"Back Office\",\"data\":{\"Outcome\":\"CO\",\"siteResponseDateTime\":\"2018-09-13T12:07:32.7798361+01:00\"}}"

    System.Net.Http.HttpContent httpContent  = new StringContent(Payload, Encoding.UTF8, "application/x-www-form-urlencoded");

    // same if I use "application/json"

    If I look at httpContent in the visual studio (2015) debugger... its an object of type System.Net.Http.HttpContent 

    Headers = Content-Type: application/x-www-form-urlencoded; charset=utf-8

    But I cannot see any of the Payload in the httpContent.

    Am I doing anything wrong ?

    Is does say Headers - then ContentLength = 153 - which is the  same length as my payload (if I remove the \ chars ), but I cannot see the payload itself....

    • Edited by goofygdog2 Thursday, September 13, 2018 12:53 PM
    Thursday, September 13, 2018 12:02 PM

All replies

  • Hi goofygdog2,

    We could get the contect via the method named ReadAsStringAsync, like this:

    string Payload = "{\"case_id\":\"FS-Case-88062659\",\"stage_name\":\"Back Office\",\"data\":{\"Outcome\":\"CO\",\"siteResponseDateTime\":\"2018-09-13T12:07:32.7798361+01:00\"}}";
    HttpContent httpContent = new StringContent(Payload, Encoding.UTF8, "application/x-www-form-urlencoded");
    string jsonContent = httpContent.ReadAsStringAsync().Result;

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by CoolDadTx Friday, September 14, 2018 1:52 PM
    Friday, September 14, 2018 7:12 AM
  • HttpContent is a wrapper around whatever is returned from the HTTP request. It could be a string, binary data or just about anything. There are various implementations of HttpContent depending upon what we want to return. So you have to know what it is and then use the appropriate Read method to get it.

    In the case of JSON or form urlencoding it'll be text so ReadAsStringAsync is the correct approach as Zhanglong showed in his code example.

    Michael Taylor http://www.michaeltaylorp3.net

    Friday, September 14, 2018 1:51 PM