Thief Program (ASP. NET + C #)

Source: Internet
Author: User
On the. NET platform, create an ASP. NET Program
1. Reference two namespaces
Using system. Text // because the encoding class is used
Using system. Net // because the WebClient class is used
2. The entire program uses three controls.
Txturl // enter the webpage address Textbox Control you want to obtain
Txtbody // get the Textbox Control of the webpage content you want to obtain
Btnreturn // button control
3. In ***. aspx. CS Code
Private void btnreturn_click (Object sender, system. eventargs E)
{
String url = txturl. Text. Trim (); // obtain the entered webpage address

WebClient WB = new WebClient (); // create a WebClient instance
// Obtain or set the network creden。 used to authenticate requests to Internet resources. (Optional)
// WB. Credentials = credentialcache. defaultcredentials;
// Download data from the resource and return a byte array. (Add @ because there is a "/" symbol in the middle of the URL)
Byte [] pagedata = WB. downloaddata (@ URL );
// Convert characters,
String result = encoding. Default. getstring (pagedata );

Txtbody. Text = result;
}
4. Add a code to the HTML code of the word ***. aspx
In the first line of code <% @ page = ............................. add validaterequest = false to %>.
Summary: The entire code is just a few lines, and you don't have to worry about code. I saw it in my help document yesterday, in fact, the WebClient class has many methods for downloading resources and uploading resources. If you are interested, you can refer to the following help documents on the WebClient class:
For the WebClient class, see
WebClient member | system. Net namespace | webrequest | webresponse | httpwebrequest |
Httpwebresponse | WebClient member (Visual J # syntax) | C ++ managed extended Programming
Requirements
Namespace: system. net
Platform: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP
Professional, Windows Server 2003 Series
Assembly: system (in system. dll)
. NET Framework security:
Webpermission is used to access the requested URI or any URI to which the request is redirected. Associated enumeration: connect.
Language
C #
C ++
JScript
Visual Basic
Show all
Provides a public method to send data to the resource identified by the URI and receive data from the resource identified by the URI. This class cannot be inherited.
For a list of all members of this type, see WebClient members.
System. Object
System. externalbyrefobject
System. componentmodel. Component
System. net. WebClient
[Visual Basic]
<Comvisible (true)>
Notinheritable public class WebClient
Inherits component
[C #]
[Comvisible (true)]
Public sealed class WebClient: Component
[C ++]
[Comvisible (true)]
Public _ GC _ sealed class WebClient: public component
[JScript]
Public
Comvisible (true)
Class WebClient extends component
Thread Security
All public static members of this type (shared in Visual Basic) are safe for multi-threaded operations. But no instance is guaranteed
The members are thread-safe.
Remarks
The WebClient class provides the ability to send data to and receive data from any local, Intranet, or Internet Resource identified by the URI
Public method.
The WebClient class uses the webrequest class to provide access to Internet resources. The WebClient instance can use any
The webrequest child that is registered using the webrequest. registerprefix method to access data.
Note that by default,. NET Framework supports Uris starting with HTTP:, https:, and file: Scheme identifiers.
The WebClient class provides four methods to upload data to resources:
Openwrite returns a stream used to send data to resources.
Uploaddata sends the byte array to the resource and returns the byte array containing any response.
Uploadfile sends the local file to the resource and returns a byte array containing any response.
Uploadvalues sends the namevaluecollection to the resource and returns a byte array containing any response.
The WebClient class also provides three methods for downloading data from resources:
Downloaddata downloads data from the resource and returns a byte array.
Downloadfile downloads data from a resource to a local file.
Openread returns data from a resource in the form of stream.
Requirements
Namespace: system. net
Platform: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP
Professional, Windows Server 2003 Series
Assembly: system (in system. dll)
. NET Framework security:
Webpermission is used to access the requested URI or any URI to which the request is redirected. Associated enumeration: connect.

Related Article

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.