First, create a windows application and a web application.
In a web application, the webpage is switched to the source code and some useless code in the source code is deleted. Only the header is retained. When a windows application reads the webpage source code, these will be read together, however, these are useless data, and deleting them does not affect the operation. The code to be retained is as follows:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
Then implement the function in Page_Load. The following is an example of adding two numbers and returning them to winform.
String A = Request. Form ["a"]. ToString (); // The parameters passed to the webpage by winform are identified by.
String B = Request. Form ["B"]. ToString ();
Int C = Convert. ToInt32 (A) + Convert. ToInt32 (B );
Response. Write (C. ToString (); // Write data to the webpage.
The example code for passing parameters in winform is as follows:
Private void button#click (object sender, EventArgs e)
{
WebClient w = new WebClient ();
System. Collections. Specialized. NameValueCollection VarPost = new System. Collections. Specialized. NameValueCollection ();
VarPost. Add ("a", textBox1.Text. Trim (); // convert the data in textBox1 to a parameter identified by a and pass it to the webpage by POST
VarPost. Add ("B", textBox2.Text. Trim ();
// Pass all data in the parameter list VarPost to http: // The requested domain name or the IIs-configured address/Default. aspx by using the POST method,
// Store the data returned from the web page in byte streams to byRemoteInfo.
Byte [] byRemoteInfo = w. UploadValues ("http: // applied domain name or address configured with IIs/Default. aspx", "POST", VarPost );
String sRemoteInfo = System. Text. Encoding. UTF8.GetString (byRemoteInfo );
Label1.Text = sRemoteInfo;
}
In this way, C # Winform simulates the form to submit data by using POST value passing, which is for your reference only.