I recently added batch request support to my Web API project, and spent the better part of a day trying to debug why the batch request was failing using Postman: Unexpected end of MIME multipart stream. MIME multipart message is not complete.
After searching around for quite a while, and learning all about the trailing CRLF issue, I finally wrote a quick C# console app using System.Net.Http
similar to the example given here. This worked great!
My question is: what is Postman doing differently that makes my batch requests fail? Using fiddler to capture the requests, and then using winmerge to diff them, the only difference is the Postman request contains a few additional headers:
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36
Cache-Control: no-cache
Origin: chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
I tried adding those headers to my console app to make the requests exactly the same, and it still worked in my console app, but failed in Postman!
Anyone have any idea WHY?
Fiddler-captured requests below:
POSTMAN:
POST http://localhost:49402/api/sequentialBatch HTTP/1.1
Host: localhost:49402
Connection: keep-alive
Content-Length: 528
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36
Cache-Control: no-cache
Origin: chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm
Session-ID: 03317cfa-c051-4813-a02a-a9fa955cc7f5
Authorization: Basic c2E6c2E=
Content-Type: multipart/mixed; boundary="c3581ff4-f6eb-4c41-ac02-0bb8b80b30ef"
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
--c3581ff4-f6eb-4c41-ac02-0bb8b80b30ef
Content-Type: application/http; msgtype=request
GET /api/currency?$filter=Currency_ID eq 'Z-US$' HTTP/1.1
Host: localhost.fiddler:49402
Authorization: Basic c2E6c2E=
Session-ID: 03317cfa-c051-4813-a02a-a9fa955cc7f5
--c3581ff4-f6eb-4c41-ac02-0bb8b80b30ef
Content-Type: application/http; msgtype=request
GET /api/countrycode/US HTTP/1.1
Host: localhost.fiddler:49402
Authorization: Basic c2E6c2E=
Session-ID: 03317cfa-c051-4813-a02a-a9fa955cc7f5
--c3581ff4-f6eb-4c41-ac02-0bb8b80b30ef--
CONSOLE APP: (with additional postman headers)
POST http://localhost:49402/api/sequentialBatch HTTP/1.1
Host: localhost:49402
Connection: Keep-Alive
Content-Length: 553
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36
Cache-Control: no-cache
Origin: chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm
Session-ID: 03317cfa-c051-4813-a02a-a9fa955cc7f5
Authorization: Basic c2E6c2E=
Content-Type: multipart/mixed; boundary="cf2b18a3-5861-49d7-878b-142283cb4959"
Accept: */*
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US, en; q=0.8
--cf2b18a3-5861-49d7-878b-142283cb4959
Content-Type: application/http; msgtype=request
GET /api/currency?$filter=Currency_ID%20eq%20'Z-US$' HTTP/1.1
Host: localhost.fiddler:49402
Authorization: Basic c2E6c2E=
Session-ID: 03317cfa-c051-4813-a02a-a9fa955cc7f5
--cf2b18a3-5861-49d7-878b-142283cb4959
Content-Type: application/http; msgtype=request
GET /api/countrycode/US HTTP/1.1
Host: localhost.fiddler:49402
Authorization: Basic c2E6c2E=
Session-ID: 03317cfa-c051-4813-a02a-a9fa955cc7f5
--cf2b18a3-5861-49d7-878b-142283cb4959--
I did notice one difference: in Postman the Content-Length
header changed from 553 (as posted) to 528 (when captured)... not sure if this is relevant to my issue or not...