开发者

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


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();


I believe if you use the HttpWebRequest class, this information will be in the referer of the header:

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx

private void printReferer(string url)
{
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); ;      
    Console.WriteLine(req.Referer);      
}

If you are trying to get the data from the page, use the WebClient class:

http://msdn.microsoft.com/en-us/library/system.net.webclient%28v=vs.80%29.aspx

It is a wrapper for HttpWebRequest/HttpWebResponse that makes life a little easier.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜