How to request to send HTTP in WinForm
Sending HTTP requests manually is primarily a HttpWebResponse method of calling System.Net
To send HTTP GET requests manually:
String strURL = "http://localhost/Play/CH1/Service1.asmx/doSearch?keyword=";
strURL +=this.textbox1.text;
System.Net.HttpWebRequest request;
Create an HTTP request
= (System.Net.HttpWebRequest) webrequest.create (strURL);
Request. Method= "Get";
System.Net.HttpWebResponse response;
Response = (System.Net.HttpWebResponse) request. GetResponse ();
System.IO.Stream s;
s = Response. GetResponseStream ();
XmlTextReader Reader = new XmlTextReader (s);
Reader.movetocontent ();
string strvalue = Reader.readinnerxml ();
strvalue = Strvalue.replace ("<", "<");
strvalue = Strvalue.replace (">", ">");
MessageBox.Show (strvalue);
Reader.close ();
Send an HTTP POST request manually
String strURL = "Http://localhost/Play/CH1/Service1.asmx/doSearch";
System.Net.HttpWebRequest request;
Request = (System.Net.HttpWebRequest) webrequest.create (strURL); Post request method request.
Method= "POST"; Content type request.
Contenttype= "application/x-www-form-urlencoded";
The parameter is encoded by a URL encoding string paraurlcoded = System.Web.HttpUtility.UrlEncode ("keyword");
paraurlcoded + = "=" + System.Web.HttpUtility.UrlEncode (this.textBox1.Text);
Byte[] payload;
Converts a URL-encoded string into a byte payload = System.Text.Encoding.UTF8.GetBytes (paraurlcoded); Sets the requested ContentLength request. ContentLength = payload.
Length; Get request Stream Stream writer = requests.
GetRequestStream (); Writes the request parameter to the stream writer. Write (payload,0,payload.
Length); Closes the request stream writer.
Close ();
System.Net.HttpWebResponse response; Get response Stream response = (System.Net.HttpWebResponse) request.
GetResponse ();
System.IO.Stream s; s = Response.
GetResponseStream ();
XmlTextReader Reader = new XmlTextReader (s);
Reader.movetocontent ();
string strvalue = Reader.readinnerxml (); strvalue = StrvalUe.
Replace ("<", "<");
strvalue = Strvalue.replace (">", ">");
MessageBox.Show (strvalue);
Reader.close ();
Above this in the WinForm to send the HTTP request Realization method is small series to share to everybody's content, hoped can give everybody a reference, also hoped that everybody supports the cloud habitat community.