public static UnityAgentResponse ReadFromWebResponse(HttpWebResponse response) { using (Stream respStream = response.GetResponseStream()) { StreamReader reader = new StreamReader(respStream); UnityAgentResponse agentResp = new UnityAgentResponse(response); agentResp._body = reader.ReadToEnd(); agentResp._response = response; return agentResp; } }
public static UnityAgentResponse ReadFromWebResponse(HttpWebResponse response) { using (Stream respStream = response.GetResponseStream()) { StreamReader reader = new StreamReader(respStream); UnityAgentResponse agentResp = new UnityAgentResponse(response); agentResp._body = reader.ReadToEnd(); agentResp._response = response; return(agentResp); } }
public UnityTask <UnityAgentResponse> Begin() { return(new UnityTask <UnityAgentResponse>( task => { if (_data != null) { using (Stream inStream = _data.GetDataStream()) { _webRequest.ContentLength = inStream.Length; using (Stream outStream = _webRequest.GetRequestStream()) { inStream.CopyToSync(outStream, BUFFER_SIZE); } } } HttpWebResponse resp = _webRequest.GetResponse() as HttpWebResponse; UnityAgentResponse resp_ = UnityAgentResponse.ReadFromWebResponse(resp); task.Resolve(resp_); })); }
private JsonData ExtractJsonFromForm(UnityAgentResponse response) { // Unfortunately when we send json data to httpbin it just // thinks it is a form variable. When it echos the request // back at us it comes back a bit mangled. // We need to extract the JSON string manually. // Get the form node that contains the data JsonData formNode = response.Json["form"]; // The JSON data is stored as the first key // of the form object // I would use LINQ but it is flakey on iOS // due to AOT compilation string jsonDataString = ""; int count = 0; foreach (var key in formNode.Keys) { jsonDataString = key; count++; } // There should not be more than one key // something is wrong otherwise Assert.AreEqual(count, 1); return JsonMapper.ToObject(jsonDataString); }