使用响应标头内容调用REST API使用RestSharp编码gzip会导致问题。如果我使用Visual Studio将代码作为简单的ConsoleApplication执行,则没有问题,因此只有Unity无法处理。有想法的人吗?
var client = new RestClient("http://rest.sandbox-immobilienscout24.de");
var request = new RestRequest("/restapi/api/search/v1.0/search/region", Method.GET);
client.ClearHandlers();
request.AddQueryParameter("realestatetype", realestatetype);
request.AddQueryParameter("geocodes", geocodes);
request.AddHeader("Accept", "application/json");
request.AddHeader("Systemauthorization", "blabla");
IRestResponse response = client.Execute(request);
Debug.Log("search:" +response.ErrorException);
响应标题:
Cache-Control →private
Content-Encoding →gzip
Content-Type →application/json;charset=UTF-8
Date →Sun, 06 Nov 2016 14:21:03 GMT
Expires →Thu, 01 Jan 1970 01:00:00 CET
L-IS24-ApiClient →blaKey
L-IS24-RequestRefnum →06be3d11-6526-4664-acd1-0787dbd7d1f6
Server →Apache
Transfer-Encoding →chunked
Vary →Accept-Encoding
例外:
search:System.Net.WebException: MonoPosixHelper ---> System.DllNotFoundException: MonoPosixHelper
at (wrapper managed-to-native) System.IO.Compression.DeflateStream:CreateZStream (System.IO.Compression.CompressionMode,bool,System.IO.Compression.DeflateStream/UnmanagedReadOrWrite,intptr)
at System.IO.Compression.DeflateStream..ctor (System.IO.Stream compressedStream, CompressionMode mode, Boolean leaveOpen, Boolean gzip) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Compression.DeflateStream:.ctor (System.IO.Stream,System.IO.Compression.CompressionMode,bool,bool)
at System.IO.Compression.GZipStream..ctor (System.IO.Stream compressedStream, CompressionMode mode, Boolean leaveOpen) [0x00000] in <filename unknown>:0
at System.IO.Compression.GZipStream..ctor (System.IO.Stream compressedStream, CompressionMode mode) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.IO.Compression.GZipStream:.ctor (System.IO.Stream,System.IO.Compression.CompressionMode)
at System.Net.HttpWebResponse..ctor (System.Uri uri, System.String method, System.Net.WebConnectionData data, System.Net.CookieContainer container) [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Net.HttpWebResponse:.ctor (System.Uri,string,System.Net.WebConnectionData,System.Net.CookieContainer)
at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
at RestSharp.Http.GetRawResponse (System.Net.HttpWebRequest request) [0x00000] in <filename unknown>:0
UnityEngine.Debug:Log(Object)
ApiClient:callSearchApi(String, String) (at Assets/ApiClient.cs:33)
ApiClient:Start() (at Assets/ApiClient.cs:12)
答案 0 :(得分:0)
Unity 2.6.1之后没有使用此功能,请尝试使用WWW或WWWForm
答案 1 :(得分:0)
您可以选择与网络互动。包括
WWW类可用于向GET和POST发送请求 服务器。 WWW类默认使用GET,如果提供,则使用POST postData参数。
UnityWebRequest是Unity原始WWW对象的替代品。 它提供了一个用于组合HTTP请求和处理的模块化系统 HTTP响应。 UnityWebRequest系统的主要目标是 允许Unity游戏与现代Web后端进行交互。它也是 支持高需求功能,如分块HTTP请求,流媒体 POST / PUT操作和对HTTP标头和动词的完全控制。