Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a value from a HTTP Request from a windows forms client

How can I hit a link such as http://somewhere.com/client.php?locationID=1 and return the value of the location id from a C# windows forms application?

Trying to get an HTTPGetRequest from a C# Windows Forms Application.

Not sure where to start or how this would be done.

Thanks

like image 943
Carl Weis Avatar asked Jul 19 '11 15:07

Carl Weis


People also ask

Can I use Web API in Windows application?

Now, we can create a Winform application to consume the Web API and upload/download the files from web server to our local machine. Open Visual Studio 2015. Click New >> Project >> Visual C# >> Windows >> select Windows Forms Application. Enter your project name and click OK.

What is HTTP request C#?

C# GET request with HttpClientHttpClient provides a base class for sending HTTP requests and receiving HTTP responses from a resource identified by a URI. Program.cs. using var client = new HttpClient(); var content = await client. GetStringAsync("http://webcode.me"); Console.


1 Answers

try this:

       HttpWebRequest request = (HttpWebRequest) WebRequest.Create(@"http://somewhere.com/client.php?locationID=1");
       HttpWebResponse response = (HttpWebResponse)request.GetResponse();
       string content = new StreamReader(response.GetResponseStream()).ReadToEnd();
like image 87
dknaack Avatar answered Nov 15 '22 05:11

dknaack