[Favorites] Scheduled from the Internet to the source code of the specified URL (C #)

xiaoxiao2021-03-06  46

Call mode:

#REGION test Get a remote web page

GetPagecode GPC = New getPageCode ();

gpc.url = "http://ppcode.com/";

GPC.ProxyState = 1; // Using proxy servers, 0 is not used, set to 1 after 1 after the following proxy settings

GPC.ProxyAddress = "http://proxyname.com"; // proxy server address

gpc.proxyport = "80"; // The port of the proxy server

gpc.proxyaccount = "proxy"; // proxy server account

gpc.proxypassword = "password"; // proxy server password

gpc.proxydomain = "BQC"; // Proxy server domain

GPC.outfilePath = filepath; // Set the place where the output file path is set, if not set, return a string

gpc.getsource (); // Process

String Temperr = gpc.noteMessage; // If an error, here will prompt

String tempcode = gpc.outstring; // Returned string

#ndregion

Class code:

Using system;

Using system.collections;

Using system.componentmodel;

Using system.data;

Using system.drawing;

Using system.io;

Using system.net;

Using system.text;

Using system.Web;

Namespace Test.com

{

///

/// Function: Source code for the URL page on the Internet

/// Create: 2004-03-22

/// Author: Rexsp MSN: yubo@x263.net

///

Public class getPagecode, PUBLIC CLASS

{

#Region private variable

///

/ / / 网 page URL address

///

Private string URL = NULL;

///

/ / Whether to use a code server: 0 Do not use 1 proxy server

///

Private int proxyState = 0;

///

/// proxy server address

///

PRIVATE STRING ProxyAddress = NULL;

///

/// proxy server port

///

Private string proxyport = NULL;

///

/// Proxy server username

///

Private string proxyaccount = null;

///

/// proxy server password

///

Private string proxypassword = null;

///

/// proxy server domain

///

Private string proxydomain = NULL;

///

/// Output file path

///

Private string outfilepath = NULL;

///

/// Output string

///

Private string outstring = null;

///

// 提 提 信息

///

PRIVATE STRING NOTEMESSAGE;

#ndregion

#Region Public property

///

/// I want to read the URL address

///

Public String URL

{

Get {return URL;}

SET {URL = Value;

}

///

/ / / Whether to use a proxy server flag

///

Public int proxyState

{

Get {return proxyState;}

Set {proxyState = value;

}

///

/// proxy server address

///

Public String ProxyAddress

{

Get {return proxyaddress;}

Set {proxyaddress = value;

}

///

/// proxy server port

///

Public String Proxyport

{

Get {return proxyport;}

Set {proxyport = value;}

}

///

/// proxy server account

///

Public String Proxyaccount

{

Get {return proxyaccount;}

Set {proxyaccount = value;

}

///

/// proxy server password

///

Public String ProxyPassword

{

Get {return proxypassword;}

Set {proxypassword = value;}

}

///

/// proxy server domain

///

Public String Proxydomain, PUBLIC STRING

{

Get {return proxydomain;

Set {proxydomain = value;

}

///

/// Output file path

///

Public String OutfilePath

{

Get {return outfilepath;}

Set {OutfilePath = value;

}

///

/// Returned string

///

Public String Outstring

{

Get {return outstring;}

}

///

/// Return prompt information

///

Public String NoteMessage

{

Get {return notemessage;}

}

#ndregion

#REGION constructor

Public getPagecode ()

{

}

#ndregion

#Region Public Method

///

/// read the specified URL address, save it to the specified file ///

Public void getsource ()

{

WebRequest Request = WebRequest.create (this.URL);

// Use the proxy server

IF (this.ProxyState == 1)

{

/ / Default reading data of the 80 port

IF (this.proxyport == null)

this.Proxyport = "80";

WebProxy myproxy = new webproxy ();

MYPROXY = (WebProxy) Request.Proxy;

MyProxy.address = New Uri (this.ProxyAddress ":" this.Proxyport);

MyProxy.credentials = new networkcredential (this.proxyaccount, this.proxypassword, this.proxydomain);

Request.Proxy = myproxy;

}

Try

{

// Request service

WebResponse response = Request.getResponse ();

//returned messages

Stream relatream = response.getResponseth_;

StreamReader SR = New StreamReader (RESSTREAM, System.Text.Encoding.default);

String Tempcode = Sr.ReadToend ();

RESSTREAM.CLOSE ();

sr.close ();

// If the output file path is empty, the obtained content is assigned to the Outstring property.

IF (this.outfilepath == null)

{

THIS.outstring = Tempcode;

}

Else

{

FileInfo Fi = New FileInfo (this.outfilepath);

// If there is a file,

IF (FI.EXISTS)

Fi.delete ();

StreamWriter SW = New StreamWriter (this.outfilepath, true, eNCoding.default);

SW.WRITE (TEMPCODE);

Sw.flush ();

SW.CLOSE ();

}

}

Catch

{

This.noteMessage = "Out, please check if the network is connected;";

}

}

#ndregion

}

}

转载请注明原文地址:https://www.9cbs.com/read-79571.html

New Post(0)