Example #1
0
        public SocialHttpResponse GetResponse()
        {
            // Merge the query string
            string url = new UriBuilder(Url).MergeQueryString(QueryString).ToString();

            // Initialize the request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            // Set the method
            request.Method      = Method;
            request.Credentials = Credentials;

            // Add any headers
            // TODO: Add headers

            // Add the request body (if a POST request)
            if (Method == "POST" && PostData != null && PostData.Count > 0)
            {
                string dataString = SocialUtils.NameValueCollectionToQueryString(PostData);
                request.ContentType   = "application/x-www-form-urlencoded";
                request.ContentLength = dataString.Length;
                using (Stream stream = request.GetRequestStream()) {
                    stream.Write(Encoding.UTF8.GetBytes(dataString), 0, dataString.Length);
                }
            }

            // Get the response
            try {
                return(new SocialHttpResponse((HttpWebResponse)request.GetResponse()));
            } catch (WebException ex) {
                return(new SocialHttpResponse((HttpWebResponse)ex.Response, ex));
            }
        }
 public static UriBuilder MergeQueryString(this UriBuilder builder, NameValueCollection values)
 {
     if (values == null || values.Count == 0)
     {
         return(builder);
     }
     builder.Query = SocialUtils.NameValueCollectionToQueryString(HttpUtility.ParseQueryString(builder.Query).Set(values));
     return(builder);
 }
        public static void AppendQueryString(this UriBuilder builder, NameValueCollection values)
        {
            if (values == null || values.Count == 0)
            {
                return;
            }
            NameValueCollection nvc = HttpUtility.ParseQueryString(builder.Query);

            nvc.Add(values);
            builder.Query = SocialUtils.NameValueCollectionToQueryString(nvc);
        }
Example #4
0
 public override string ToString()
 {
     return(SocialUtils.NameValueCollectionToQueryString(_nvc));
 }