任务:在没有BCL的情况下在net framework 4.0上创建multipart / mixed http请求。 所以它意味着“不使用System.Net.Http”
在简单请求的情况下,我可以使用HttpWebRequest
WebResponse Send(byte[] data)
{
var request = WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = //....
request.Headers.Add("myHeader","myHeaderContent);
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
stream.Write(data, 0, data.Length);
return request.GetResponse();
}
但是我怎样才能使multipart / mixed得到这样的请求:
POST http://google.com:9010/api/lalala HTTP/1.1
Accept: application/json
Content-Type: multipart/mixed; boundary="batch-1"
Host: google.com:9010
Vendor: vendor1
Product: Test
Product-Version: 1.0.0
Plugin-Version: 0.0.1
Content-Length: 208
--batch-1
Content-Type: application/http; msgtype=request
POST /api/SubrequestPath/49f962b5wdd527 HTTP/1.1
Host: google.com:9010
[{"jsonData":"data"}]
--batch-1--
Content-Type: application/http; msgtype=request
POST /api/Subreques2tPath/asdqwe HTTP/1.1
Host: google.com:9010
[{"jsonData":"some other data"}]
是否有任何HttpWebRequest功能或开源轻量级包?
答案 0 :(得分:0)
我已经使用自定义BCL-free http-client
完成了它nugget :TinyClient
git :https://github.com/tmteam/TinyClient
随意合并并请求功能。