473,394 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to make a Http request from a .net window form application

I have a .net window form application but I have to get
data from various web sites. How do I make Http request
(preferrably via post method) from a window form to get
the data from those web sites?
What namespace and dll do I have to include?
A walkthrough and coding example will be helpful.
...

Nov 16 '05 #1
1 5518
edx
> I have a .net window form application but I have to get
data from various web sites. How do I make Http request
(preferrably via post method) from a window form to get
the data from those web sites?
What namespace and dll do I have to include?
A walkthrough and coding example will be helpful.

Hi,

This is a sample that I have done recently:

Namespace of the types is:

using namespace System::Net;

System::Net::HttpWebRequest *Request =

__try_cast <System::Net::HttpWebRequest *>

(System::Net::HttpWebRequest::Create (Shttp://www.somesite.com));

String *Content, *Identifier;

// Do the actual request

//

String *Query = "IDENT=";

Query = String::Concat (Query, Ident);

Query = String::Concat (Query, "&USERLOGID=");

Query = String::Concat (Query, UserLogid);

Query = String::Concat (Query,
"&ENTRYLENGTH=-1&EXTRAINPUT=&EXTRAINPUTLENGTH=-1&ENTRY=");

Query = String::Concat (Query, Question);

Request->Method = S"POST";

Request->ContentType = S"application/x-www-form-urlencoded;
charset=\"utf-8\"";

Request->ContentLength = Query->Length;

StreamWriter *sw = new StreamWriter (Request->GetRequestStream ());

sw->Write (Query);

sw->Close ();

WebResponse *Response;

try {

Response = Request->GetResponse ();

} catch (Exception *) {

p->GetIdent ();

return;

}

Content = (new StreamReader (Response->GetResponseStream ()))->ReadToEnd ();

Content contains the response of the webserver.

I hope that helped,
Felix Arends
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: turnit \(removethis\) | last post by:
I have a login form that uses the post method to carry the information to the next page. The form works just fine in ie6.0, but fails in mozilla and fails in ie5.2 on a mac. "HTTP/1.1 400 Bad...
1
by: Matt | last post by:
My problem is when the user click the submit button, it will launch another new window for the request page. I want to confirm we cannot use JavaScript open window functions to open a request page?...
3
by: nicholas4 | last post by:
I'm trying to make a web page where a form lets you enter a url address in a field and upon clicking the submit button, the text of the source code of the page is displayed below the form. I know...
7
by: kaburke | last post by:
Is there a way to make a page at the receiving end of a Server.Transfer think that the request is a Postback? (When I say "think it is a Postback," I mean I want the page to go through the ENTIRE...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
6
by: divya | last post by:
I have a page name edit.asp which should expire immediately .The user cannot open this page directly he has to provide a password for entering this page.thus when the user enters edit.asp , it has...
0
DressageRider
by: DressageRider | last post by:
I need your help. Desperately. Someone has to be able to fix the utter balls up I've made after dinking around in Flash for the last four days. I have no prior knowledge of anything other than...
11
by: Simon van Beek | last post by:
Dear reader, By opening an application I get always the main Access window with the closing cross in the above right corner. Is there a possibility to make this closing cross invisible? ...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.