Skip to content

Instantly share code, notes, and snippets.

@turkdogan
Created February 23, 2017 21:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save turkdogan/1b972399aa7fdf0796335d0cba58166e to your computer and use it in GitHub Desktop.
Save turkdogan/1b972399aa7fdf0796335d0cba58166e to your computer and use it in GitHub Desktop.
A Simple Get Request in C#
public static void RequestWeather()
{
const string url = "http://api.geonames.org/weatherJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=demo";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
var webResponse = request.GetResponse();
var webStream = webResponse.GetResponseStream();
var responseReader = new StreamReader(webStream);
var response = responseReader.ReadToEnd();
Console.WriteLine("Response: " + response);
responseReader.Close();
}
@cw-arvindkumar
Copy link

it will not work if pass # in url.
ex:-http://api.geonames.org/#divBar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment