4

I am trying to implement creating a multipart request where each part is a HTTP request

To see what I mean here's for example how this Google API works: https://cloud.google.com/dns/api/batch#example (I don't use that API, it's just an example)

I've seen examples using MultipartFormDataContent but I don't understand how to create each part"

--====1340674896===
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: 1111

POST /contacts/479038 HTTP/1.1
Content-Type: application/json
Accept: application/json

{ "SomeData" : 1 }

The content of each part is I think the serialized string of a request:

GET /contacts/479038 HTTP/1.1
Content-Type: application/json
Accept: application/json

{ "SomeData" : 1 }

So how do I create this? I guess I need to get the serialized version of a HttpRequestMessage? Can I just serialize request.Content.ReadAsStringAsync())

In WebAPI I see there's this HttpContentMessage which takes a HttpRequestMessage and can serialize it:

var httpMessageContent = new HttpMessageContent(request);
var buffer = httpMessageContent.ReadAsByteArrayAsync().Result;
stream.Write(buffer, 0, buffer.Length);

But I don't have this class available in .NETStandard

Don Box
  • 3,166
  • 3
  • 26
  • 55

0 Answers0