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); }
/// <summary> /// Calculates the distance in meters between two GPS locations. /// </summary> /// <param name="loc1">The first location.</param> /// <param name="loc2">The second location.</param> public static double GetDistance(this ILocation loc1, ILocation loc2) { return(SocialUtils.GetDistance(loc1, loc2)); }
public override string ToString() { return(SocialUtils.NameValueCollectionToQueryString(_nvc)); }