tonydev314
tonydev314

Reputation: 249

How can I post a multipart form using Anglesharp

I've built an application that deals with various websites using Anglesharp. Now I have to post a multipart form and I'm a little stuck on how to go about this.

Normally I'd use the Anglesharp DocumentRequest object to create a request this has the following options:

DocumentRequest Get(Url target, INode? source = null, String? referer = null)
DocumentRequest Post(Url target, Stream body, String type, INode? source = null, String? referer = null)
DocumentRequest PostAsPlaintext(Url target, IDictionary<String, String> fields)
DocumentRequest PostAsUrlencoded(Url target, IDictionary<String, String> fields)

The DocumentRequest itself appears to be passed through Anglesharp code until eventually ends up delivered to the HttpRequest so I tried the following with my MultiPartFormDataContent

var request = DocumentRequest.Post(new Url(_CreateURL), formData.ReadAsStream(), "multipart/form-data");

However I'm struggling to get this to work without a lot of hacking and manually setting of fields normally dealt with by Anglesharp. I'm also getting multiple identical cookies included in my request for some reason.

So the question is is there an easier way to submit multipart form/data via Anglesharp. A way to extend the library?

Upvotes: 0

Views: 46

Answers (0)

Related Questions