0

I am not getting the response I am wanting for the following code:

var multipart = new MultipartFormDataContent();
var empty = Encoding.ASCII.GetBytes("\r\n\r\n\r\n");
HttpContent content = new ByteArrayContent(empty);
content.Headers.Add("name", "jform[ical_url]");
multipart.Add(content);
...[cut for brevity]...
using (var handler = new HttpClientHandler { UseCookies = false })
   using (var client = new HttpClient(handler) { BaseAddress = new System.Uri("http://icalendar.org") })
   {
       var response = await client.PostAsync("/validator", multipart);

I know exactly what I would like the POST request to look like (having used Firebug's 'copy cURL' menu item).

Is there a way to see what the client.PostAsync will send, or an extension to serialise the multipart variable above so that I can compare with the cURL string from a successful post?

Thank you.

Brent
  • 4,611
  • 4
  • 38
  • 55

1 Answers1

0

Overriding the delegating handler has provided some of the answer, as per this SO answer.

I had not clearly explained that this was a class library. I tried Crowcoders advice, but I couldn't get it to work, and as the entire solution contains no WebAPI or MVC or similar projects, and I am trying to post to a validation site to check certain unit tests meet a spec. Briefly looking through the Stackify Prefix docs, I think the ability to handle this kind of scenario is in the pipeline, but not released as yet.

As I would love to know if any defaults are being added to the header (Accept, Language etc), I might look at Fiddler.

Community
  • 1
  • 1
Brent
  • 4,611
  • 4
  • 38
  • 55