private void GetResponseStatus(OneSkyResponse oneSkyResponse, WebResponse response) { var httpResponse = (HttpWebResponse)response; if (httpResponse != null) { oneSkyResponse.StatusCode = (int)httpResponse.StatusCode; oneSkyResponse.StatusDescription = httpResponse.StatusDescription; } }
private IOneSkyResponse Send(string method, byte[] data = null) { var request = (HttpWebRequest)WebRequest.Create(this.url); request.Accept = "Accept=application/json"; request.ContentType = this.contentType; request.Method = method.ToUpper(); if (method != "GET" && data != null) { using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); stream.Flush(); } } var oneSkyResponse = new OneSkyResponse(); var result = new StringBuilder(); try { var response = request.GetResponse(); var responseStream = response.GetResponseStream(); if (responseStream != null) { using (var responseReader = new StreamReader(responseStream)) { while (!responseReader.EndOfStream) { var line = responseReader.ReadLine(); if (line != null) { result.Append(line); result.Append('\n'); } } } } this.GetResponseStatus(oneSkyResponse, response); } catch (WebException ex) { var stream = ex.Response.GetResponseStream(); if (stream == null) { throw; } using (var responseReader = new StreamReader(stream)) { while (!responseReader.EndOfStream) { var line = responseReader.ReadLine(); if (line != null) { result.Append(line); } } } this.GetResponseStatus(oneSkyResponse, ex.Response); } oneSkyResponse.Content = result.ToString(); return(oneSkyResponse); }