I would like to receive data that is gzip compressed on the server side with Unity's C#(Mono) using the GetResponse() method in HttpWebRequest.
of the following sources:
using(HttpWebResponse wres=(HttpWebResponse)req.GetResponse())
when you run
DllNotFoundException:MonoPosixHelper
I am unable to receive a response with the error
According to research, Mono has a GZipStream namespace, but there seems to be no implementation part.
*The reason is that although the compilation goes through, it falls off when I try to use GzipStream, so I think there is only InterFace.
The requestor was able to gzip using Ionic.Zip.CF.dll and send the data to the server, but looking at the stack trace below, the GetResponse() method seems to be designed to call System.IO.Compression.GZipStream, so I don't know how to avoid it.
Development Environment: Windows 7 Unity 5.0.2 f1
● Source Code
string serialized=Json.Serialize(JsonDataDic);
HttpWebRequest request=(HttpWebRequest) WebRequest.Create("API URL");
req.ContentType="application/json; charset=UTF-8";
req.Method="POST";
req.Accept = "application/json";
req.AutomaticDecompression=DecompressionMethods.GZip |DecompressionMethods.Deflate;
req.Headers.Add(HttpRequestHeader.ContentEncoding, "gzip");
byte [] text = Encoding.UTF8.GetBytes(serialized);
byte [ ] compress=Compress(text);
req.ContentLength=compress.Length;
// Configuring Data
vars=req.GetRequestStream();
s.Write(compress,0,compress.Length);
s.Close();
HttpWebResponse wresa=(HttpWebResponse) req.GetResponse();
using(HttpWebResponse wres=(HttpWebResponse)req.GetResponse())
{
using(Streamst=wres.GetResponseStream())
{
using(MemoryStream=newMemoryStream())
{
byte [ ] buffer = new byte [4096];
int count = 0;
do
{
count = st.Read (buffer, 0, buffer.Length);
memoryStream.Write(buffer,0, count);
} while(count!=0);
string str = Encoding.UTF8.GetString(memoryStream.ToArray());
var deserializedDoubleList=Json.Deserialize(str) as Dictionary<string, object>;;
}
}
}
● Stack trace
DllNotFoundException—MonoPosixHelper
System.IO.Compression.DeflateStream..ctor (System.IO.Stream compressedStream, CompressionMode mode, Boolean leaveOpen, Boolean gzip)
(wrapper remoteing-invoke-with-check) System.IO.Compression.DeflateStream:.ctor (System.IO.Stream, System.IO.Compression.CompressionMode, boole, boolean)
System.IO.Compression.GZipStream..ctor (System.IO.Stream compressedStream, CompressionMode mode, Boolean leaveOpen)
System.IO.Compression.GZipStream..ctor (System.IO.Stream compressedStream, CompressionMode mode)
(wrapper remoteing-invoke-with-check) System.IO.Compression.GZipStream:.ctor (System.IO.Stream, System.IO.Compression.CompressionMode)
System.Net.HttpWebResponse..ctor (System.Uriuri, System.String method, System.Net.WebConnectionData, System.Net.CookieContainer container)
(wrapper remoteing-invoke-with-check) System.Net.HttpWebResponse:.ctor (System.Uri, string, System.Net.WebConnectionData, System.Net.CookieContainer)
System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData)
Retrow as WebException: MonoPosixHelper
System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult)
System.Net.HttpWebRequest.GetResponse()
By creating a request not to include Accept-Encoding:gzip
, and having the server compress and return it, the API was able to send compressed data and receive compressed data.
This post is based on @user3732298's Comment and posted as Community WikiYes,
This post was edited based on Comments by @user3732298 and posted as Community Wiki.
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.