Matlab GZIP http postrequest

6 ビュー (過去 30 日間)
Simon Parten
Simon Parten 2018 年 11 月 28 日
回答済み: Simon Parten 2018 年 12 月 4 日
Hi Guys,
I want to send a reasonably large matrix (120 * 10000) over http, encoded as JSON.
request =
RequestMessage with properties:
Method: POST
RequestLine: 'POST'
Header: [1×3 matlab.net.http.HeaderField]
Body: [1×1 matlab.net.http.MessageBody]
Completed: 0
It's very slow,m in fact, slow enough that the server never actually finishes getting the request. I believe the best way to speed it up, would be to gzip the request body....
Can matlab do this?
Simon

採用された回答

Simon Parten
Simon Parten 2018 年 12 月 4 日
This example of outrageous hackery does appear to do the job. A bit stinky though...
myJson = jsonencode(toSend);
outStream= java.io.ByteArrayOutputStream();
gzipped = java.util.zip.GZIPOutputStream(outStream);
gzipped.write( uint8(myJson));
gzipped.close();
closedBytes = outStream.toByteArray();
messageBody.Payload = typecast (closedBytes, 'uint8');
request.Header.addFields(...
matlab.net.http.field.GenericField('Content-Encoding', 'gzip'), ...
matlab.net.http.field.ContentTypeField('application/json'))
response = send(request, uri, opts);
% To decode the stream to check ...
% someStream = java.io.ByteArrayInputStream(typecast( messageBody.Payload , 'int8'));
% gzipInStream = java.util.zip.GZIPInputStream( someStream );
% inReader = java.io.InputStreamReader(gzipInStream, 'UTF-8');
%
% aTest = char();
%
% data=inReader.read;
% while data ~=-1
% aTest = [aTest, char(data)];
% data = inReader.read;
% end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall Web Services from MATLAB Using HTTP についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by