3

I have an API (Asp.Net, written in C#) which receive a POST request on it, the request is multipart/form-data. My code to handle the request is the following:

if (request.Content.Headers.ContentType.MediaType.ToString() == "multipart/form-data")
{
    var providerMulti = Request.Content.ReadAsMultipartAsync();
    providerMulti.Wait();
    var result = providerMulti.Result;
} 

As the Wait() is called, I receive this Exception:

Invalid 'HttpContent' instance provided. It does not have a 'multipart' content-type header with a 'boundary' parameter.\r\nParameter name: content

I don't understand.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user1458259
  • 139
  • 1
  • 5
  • 1
    This is really late, but for the benefit people seeking answers, "The multipart content types needs to be specified with a boundary value as well", but here based on your if condition it looks like a custom constructed content type. Here is a sample content type constructed by Postman `Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryQSVEr5LUBQLvkqQg`. Notice the `boundary` attribute here. That is what ASP is complaining about. – M22an Sep 12 '16 at 09:25
  • I got the hint from this page,http://www.asp.net/web-api/overview/advanced/sending-html-form-data-part-2 – M22an Sep 12 '16 at 09:27
  • Related thread [here](https://stackoverflow.com/q/24503961/465053) with exactly same error text. – RBT Nov 30 '17 at 12:13
  • Are you using POSTMAN tool (a Google Chrome extension/app) at client side to sent POST requests? If you are using postman client tool to send request to your service then explicitly setting `content-type` to `multipart/form-data` is what messes up the request. Just avoid setting content-type explicitly as suggested [here](https://stackoverflow.com/a/43868741/465053). Just let me know if this solved your then I'll convert my comment in to an answer. – RBT Dec 01 '17 at 10:11

0 Answers0