Skip to content

Instantly share code, notes, and snippets.

@bithavoc
Created February 24, 2014 15:57
Show Gist options
  • Select an option

  • Save bithavoc/9191027 to your computer and use it in GitHub Desktop.

Select an option

Save bithavoc/9191027 to your computer and use it in GitHub Desktop.
public string WebGetString(Uri endpoint, string path, params WebParam[] queryParams)
{
System.Net.WebClient client = new System.Net.WebClient();
StringBuilder relativePath = new StringBuilder(path);
var filteredParams = (from p in queryParams where p.Value != null select p).ToArray();
if (filteredParams != null && filteredParams.Length > 0)
{
relativePath.Append("?");
foreach (var param in filteredParams)
{
var escapedValue = System.Net.WebUtility.UrlEncode(param.Value);
relativePath.AppendFormat("{0}={1}", param.Key, escapedValue);
relativePath.Append("&");
}
}
var uri = new Uri(endpoint, relativePath.ToString());
var responseString = client.DownloadString(uri);
return responseString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment