As with. NET Interaction: Detailed URLRequest

Source: Internet
Author: User

In. NET we know that there is a thing called webhttprequest, with which we can achieve a variety of network peeping, monitoring, acquisition and robotics, if the addition of a pattern recognition, it is really hanging ...

In as we can also achieve the same function, and we can cooperate with JS to do cross-domain, collect cookies and so on some user behavior analysis, is also a web development in a sharp weapon.

One: Building communication with external programs

1: Generally take three steps

<1> create the Request object using URLRequest.

<2> load the Request object with Urlloader and then make the request.

<3> listens to Urlloader objects, and feedback the results of the processing through various events.

II: Building URLRequest

Here's a look at the common properties in URLRequest

1:url

This is very simple, the request URL, can be absolute or can be relative.

2:method

As Ajax knows, it is used to control whether a form is submitted by post or get, what get cannot be greater than 2k,post unrestricted, and so on.

3:requestheader

We know that a mock commit will append various parameters to the HTTP head to deceive the server, pretending to be a real human request.

4:data

That is, the data that comes with the server at the time of the request, in JSON format, the kv form of the URL can be, but must be encapsulated with Urlvariables.

5: Simple Demo

var url= "http://localhost:25212/index.aspx";   
       
var vari:urlvariables=new  urlvariables ();   
       
Vari.data= "{\" id\ ": \" 2\ "}";
       
var req:urlrequest=new urlrequest (URL);   
       
Req.data=vari;   
       
Req.method=urlrequestmethod.post;

Three: Building Urlloader objects

<: In as, all urlrequest need to be loaded with urlloader to interact with back-end programs, and 5 events are provided to monitor the status of the current request.

1:open Events

Events executed at the start of the request operation

2:progress Events

Commonly used to monitor download progress, you can view "loaded data" and "total data" in real time through byteloaded and bytetotal.

3:complete Events

The events that are invoked after the data has been successfully loaded are also most commonly used.

4:ioerror Events

Like Ajax, an event that is invoked when a request fails.

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.