Facebook.FacebookApi.Request C# (CSharp) Method

Request() private method

Make an HTTP request, with the given query args
private Request ( string url, HttpVerb httpVerb, string>.Dictionary args, string &contentType ) : string
url string The URL of the request
httpVerb HttpVerb The HTTP verb to use
args string>.Dictionary Dictionary of key/value pairs that represents /// the key/value pairs for the request
contentType string
return string
        internal string Request(string url, HttpVerb httpVerb, Dictionary<string, string> args, out string contentType)
        { 
            if (args != null && args.Keys.Count > 0 && httpVerb == HttpVerb.Get)
            {
                url = url+ (url.Contains("?") ? "&" : "?") + EncodeDictionary(args);
            }

            var request = (HttpWebRequest)WebRequest.Create(url);
            request.Proxy = Proxy;
            request.Timeout = (int)Timeout.TotalMilliseconds;
            request.Headers.Add(HttpRequestHeader.AcceptLanguage, Culture.IetfLanguageTag.ToLowerInvariant());
            request.Accept = "text/javascript";
            request.Method = httpVerb.ToString();

            if (httpVerb == HttpVerb.Post)
            {
                string postData = EncodeDictionary(args);
                byte[] postDataBytes = Encoding.UTF8.GetBytes(postData);

                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = postDataBytes.Length;

                try
                {
                    using (Stream requestStream = request.GetRequestStream())
                    {
                        requestStream.Write(postDataBytes, 0, postDataBytes.Length);
                    }
                }
                catch(WebException ex)
                {
                    if (ex.Status == WebExceptionStatus.Timeout)
                        throw OperationTimeout(ex);

                    throw;
                }
                catch (Exception ex)
                {
                    throw TransportError(ex);
                }
            }

            HttpWebResponse response;
            try
            {
                using (response = (HttpWebResponse)request.GetResponse())
                {
                    contentType = ExtractContentType(response);
                    return new StreamReader(response.GetResponseStream()).ReadToEnd();
                }
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    response = (HttpWebResponse)ex.Response;
                    contentType = ExtractContentType(response);

                    if (contentType == "text/javascript")
                    {
                        using (response)
                        {
                            return new StreamReader(response.GetResponseStream()).ReadToEnd();
                        }
                    }
                }

                throw TransportError(ex);
            }
            catch (Exception ex)
            {
                throw TransportError(ex);
            }
        }