private void GetResponseStatus(CrowdinResponse crowdinResponse, WebResponse response)
        {
            var httpResponse = (HttpWebResponse)response;

            if (httpResponse != null)
            {
                crowdinResponse.StatusCode        = (int)httpResponse.StatusCode;
                crowdinResponse.StatusDescription = httpResponse.StatusDescription;
            }
        }
Exemplo n.º 2
0
 private void GetResponseStatus(CrowdinResponse crowdinResponse, WebResponse response)
 {
     var httpResponse = (HttpWebResponse)response;
     if (httpResponse != null)
     {
         crowdinResponse.StatusCode = (int)httpResponse.StatusCode;
         crowdinResponse.StatusDescription = httpResponse.StatusDescription;
     }
 }
Exemplo n.º 3
0
        private ICrowdinResponse 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 crowdinResponse = new CrowdinResponse();
            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(crowdinResponse, 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(crowdinResponse, ex.Response);
            }

            crowdinResponse.Content = result.ToString();

            return crowdinResponse;
        }
        private ICrowdinResponse 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 crowdinResponse = new CrowdinResponse();
            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(crowdinResponse, 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(crowdinResponse, ex.Response);
            }

            crowdinResponse.Content = result.ToString();

            return(crowdinResponse);
        }