Start with the code
Client request page client. aspx
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
<SCRIPT type = "text/JavaScript">
Function pageload (){
}
Function oncompletecallback (Executor, eventargs)
{
If (Executor. get_responseavailable ())
{
VaR DIV = $ get ("div1 ");
Div. innerhtml = executor. get_responsedata () + "<br/> <B>"
+ Executor. getAllResponseHeaders () + "</B> ";
}
}
Function call ()
{
VaR Req = new SYS. net. webrequest ();
Req. set_url ("server. aspx ");
Req. set_httpverb ("Post ");
Req. add_completed (oncompletecallback );
VaR body = "name =" + encodeuricomponent ($ get ("text1"). value );
Req. set_body (body );
Req. get_headers () ["Content-Length"] = body. length;
Req. Invoke ();
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: scriptmanager id = "scriptmanager1" runat = "server"/>
</Div>
<Input id = "Text1" type = "text"/>
<Input id = "Button1" type = "button" value = "Submit" onclick = "call ()"/>
<Div id = "div1"> </div>
</Form>
</Body>
</Html>
Server. aspx code
Protected void Page_Load (object sender, EventArgs e)
{
Response. Clear ();
Response. Write ("Hello," + Request ["name"]);
}
Execution result
Experience:
Callback Function writing
Function onCompleteCallback (executor, eventArgs)
Set POST request Server
Req. set_httpVerb ("Post ");
Put data inside Post
Var body = "Name =" + encodeURIComponent ($ get ("Text1"). value );
Req. set_body (body );
The get and post methods in Form correspond to the GET and POST methods in the HTTP protocol during data transmission. The main differences between the two are as follows:
1. Get is used to obtain data from the server, while Post is used to transmit data to the server.
2. Get adds the data in the form to the URL pointed to by action in the form of variable = value, and the two use "?" And each variable is connected by "&". Post puts the data in the form data body and passes the data to the URL indicated by the action according to the corresponding variables and values.
3. Get is insecure because data is stored in the request URL during transmission, nowadays, many existing servers, proxy servers, or user proxies record the request URL to a log file and place it in a certain place, so that some private information may be seen by a third party. In addition, you can directly view the submitted data in the browser. Some internal messages are displayed in front of the user. All Post operations are invisible to users.
4. Get transmission has a small amount of data, mainly because it is restricted by the URL length; while Post can transmit a large amount of data, so only Post can be used for uploading files (of course, there is another reason, as mentioned later ).
5. Get restricts that the dataset value of Form forms must be ASCII characters, while Post supports the entire iso000046 character set.
6. Get is the default Form method.
Check whether XmlHttp returns success
If (executor. get_responseAvailable ())
The following is the Sys. Net. WebRequestExecutor class
SYS. net. webrequestexecutor class members
Name
Description
- Sys. Net. WebRequestExecutor. abort Method
Stops additional processing of the current request.
- Sys.net.webrequestexecutor.exe cuterequest Method
Executes a Web request.
- SYS. net. webrequestexecutor. getAllResponseHeaders Method
Gets all the Response Headers for the current request.
- SYS. net. webrequestexecutor. getResponseHeader Method
Gets the value of a specific response header Based on the header's name.
- SYS. net. webrequestexecutor aborted Property
Gets a value indicating whether the request associated with the executor was aborted.
- SYS. net. webrequestexecutor responseavailable Property
Gets a value indicating whether the request completed successfully.
- SYS. net. webrequestexecutor responsedata Property
Gets the text representation of the response body.
- SYS. net. webrequestexecutor started property
Gets a value indicating whether the executor has started processing the request.
- Sys. Net. WebRequestExecutor statusCode Property
Gets a success status code.
- Sys. Net. WebRequestExecutor statusText Property
Gets status information about a request that completed successfully.
- Sys. Net. WebRequestExecutor timedOut Property
Gets a value indicating whether the request timed out.
- Sys. Net. WebRequestExecutor xml Property
Attempts to get the response to the current request as an XMLDOM object.