我最近向我的Web API项目添加了批处理请求支持,并花了大部分时间尝试使用Postman调试批处理请求失败的原因:Unexpected end of MIME multipart stream. MIME multipart message is not complete.
经过一段时间的搜索,并了解trailing CRLF issue的所有内容后,我终于使用System.Net.Http
编写了一个快速的C#控制台应用程序,类似于给定here的示例。这很棒!
我的问题是: Postman做什么不同会导致我的批量请求失败? 使用fiddler捕获请求,然后使用winmerge来区分它们,唯一的区别是Postman请求包含一些额外的头文件:
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
我尝试将这些标题添加到我的控制台应用程序中以使请求完全相同,并且它仍在我的控制台应用程序中工作,但在Postman中失败了!
任何人都有任何想法为什么?
Fiddler捕获的请求如下:
邮差:
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:(附加邮递员标题)
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--
我确实注意到一个区别:在邮差中,Content-Length
标题从553(已发布)更改为528(已捕获时)...不确定这是否与我的问题相关...
答案 0 :(得分:2)
有一些问题,但我正在使用Fiddler。似乎空的返回角色有所不同:
这似乎也是Postman请求与您的控制台应用程序之间的区别。