3

Is there a way to get the string representation of a MultipartFormDataContent for debugging purposes?

I have tried var x = multipart.ToString(); but it returned System.Net.Http.MultipartFormDataContent instead of something like the following below.

-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="text"

text default
-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="file1"; filename="a.txt"
Content-Type: text/plain

Content of a.txt.

-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="file2"; filename="a.html"
Content-Type: text/html

<!DOCTYPE html><title>Content of a.html.</title>

-----------------------------9051914041544843365972754266--
Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135

1 Answers1

3

you should try creating an async function to test that, as below:

    public static async Task<string> getInput()
    {
         var input = "";

         using (var content = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString()))
         {
             content.Add(new StreamContent(new MemoryStream(Encoding.ASCII.GetBytes("your data"))), 
                                              "file", "upload.xml");

             input = await content.ReadAsStringAsync();

         }

        return input;
    }

    public static void Main(string[] args)
    {
         Console.WriteLine(getInput().Result);
    }