简体   繁体   English

REST API放置大数据

[英]REST API Put large data

I have a REST API implemented in microsoft Web API. 我在Microsoft Web API中实现了REST API。
In my client i use HttpRequestMessage and HttpResponseMessage. 在我的客户端,我使用HttpRequestMessage和HttpResponseMessage。
When i am sending a small class, I serialize it to JSON and then send it. 当我发送一个小类时,我将它序列化为JSON然后发送它。
Soon, my class becomes bigger, and I need to JSON the class, zip it (in memory) and send to server. 很快,我的班级变得更大,我需要JSON这个类,压缩它(在内存中)并发送到服务器。 I can no longer use the same technique, I need to send the zip in chunks. 我不能再使用相同的技术,我需要发送块的zip。

What is the proper way to achieve it ? 实现它的正确方法是什么? I have read this post Posting a File and Associated Data to a RESTful WebService preferably as JSON 我已经阅读了这篇文章, 将文件和相关数据发布到RESTful WebService,最好是JSON

Need some good articles, I dont know where to start. 需要一些好文章,我不知道从哪里开始。

On the client side this should work pretty much out of the box... 在客户端,这应该是开箱即用的...

        var httpClient = new HttpClient();

        httpClient.DefaultRequestHeaders.TransferEncodingChunked = true;

        var content = new CompressedContent(new StreamContent(new FileStream("c:\\big-json-file.json",FileMode.Open)),"UTF8");

        var response = httpClient.PostAsync("http://example.org/", content).Result;

You can find an implementation of CompressedContent in WebApiContrib . 您可以在WebApiContrib中找到CompressedContent的实现 If you are using earlier than .net 4.5 the request will be buffered client side before sending. 如果您使用的是早于.net 4.5,请求将在发送之前缓冲客户端。 Unfortunately the underlying HttpWebRequest doesn't support buffered streaming until .net 4.5 不幸的是,底层的HttpWebRequest在.net 4.5之前不支持缓冲流式传输

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM