You can steal data after logging in.

Source: Internet
Author: User
Tags response code
This can be used to make
Automatically log on to the Forum and post it back.
Automatic Voting
Automatically log in and steal information
Wait, let's do it by yourself ............

We strongly recommend that you study it carefully, which is of great help. (Personally, it is very helpful to me)

/*
*
* Http operation module: simplifies get and post requests.
*
**/

Using system;
Using system. net;

Namespace stealweb
{
/// <Summary>
/// Summary of httpproc.
/// </Summary>
Public class httpproc
{
/// <Summary>
/// Create a request
/// </Summary>
/// <Returns> request object </returns>
Private httpwebrequest createrequest ()
{
HttpWebRequest request = null;

Request = (HttpWebRequest) HttpWebRequest. Create (this. _ strUrl); // Create a request
Request. Accept = "*/*"; // Accept any file
Request. UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2;. net clr 1.1.4322)"; // simulate IE browsing
// Request. AllowAutoRedirect = false; // 302 is not allowed here
Request. CookieContainer = new CookieContainer (); // cookie container,
Request. Referer = this. strRefUrl; // reference of the current page

// Use proxy
WebProxy myProxy = new WebProxy ();
If (config. Proxy_DEF! = "0 ")
//{
/// Use a browser proxy
// MyProxy = (WebProxy) request. Proxy;
/// Console. WriteLine ("\ nThe actual default Proxy settings are {0}", myProxy. Address );
//
//}
// Else
{
// Use custom code
MyProxy. Address = new Uri (String. Format ("http: // {0 }:{ 1}", config. Proxy_Server, config. Proxy_Port ));

// MyProxy. Credentials = new NetworkCredential (username, password );
If (config. Proxy_Username.Length> 0 & config. Proxy_Pass.Length> 0)
{
MyProxy. Credentials = new NetworkCredential (config. Proxy_Username, config. Proxy_Pass );
}

Request. Proxy = myProxy;
}

// Console. WriteLine ("\ nThe Address of the new Proxy settings are {0}", myProxy. Address );

// Send the cookie if it is attached
If (this. _ cookiePost! = Null)
{
System. Uri u = new uri (_ strurl );
// Doenet cookie processing BUG: the requested server and cookie host must be kept; otherwise, it will not be sent or retrieved!

// Change it to the same one here!
Foreach (system. net. Cookie C in _ cookiepost)
{
C. Domain = u. Host;
}

Request. CookieContainer. Add (_ cookiePost );
}

// If data needs to be sent, it will be sent in Post Mode
If (_ strPostdata! = Null & _ strPostdata. Length> 0)
{
Request. contenttype = "application/X-WWW-form-urlencoded"; // as a form request
Request. method = "Post"; // The method is post

// Send http data: Write post data to the request stream
Byte [] B = This. _ encoding. getbytes (this. _ strpostdata );
Request. contentlength = B. length;
System. Io. Stream Sw = NULL;
Try
{
Sw = request. getrequeststream ();
Sw. Write (B, 0, B. Length );
}
Catch (system. Exception ex)
{
This. _ strerr = ex. message;
}
Finally
{
If (SW! = NULL) {Sw. Close ();}
}

}
Return request; // return the created request object

}

/// <Summary>
/// Process the request
/// </Summary>
/// <Returns> return the text currently processed </returns>
Public String proc ()
{

Httpwebrequest request = createrequest (); // request
HttpWebResponse response = null ;;

System. IO. StreamReader sr = null;


Try
{
// Get the response here

Response = (httpwebresponse) request. getresponse ();

Sr = new system. Io. streamreader (response. getresponsestream (), this. Encoding );

This. _ reshtml = Sr. readtoend (); // it is assumed that the response is in HTML text.
}
Catch (system. Exception ex)
{
This. _ strErr = ex. Message; // if an error occurs, null text is returned.
Return "";
}
Finally
{
If (sr! = Null) {sr. Close ();}
}
// Status code
This. _ strCode = response. StatusCode. ToString ();

If (this. _ strCode = "302") // if it is 302 redirection, a new address is returned.
{
This. _ ResHtml = response. Headers ["location"];
}

// Obtain the cookie
If (response. Cookies. Count> 0)
{
This. _ cookieget = response. Cookies; // get a new COOKIE: note that cookie merging is not considered here.
}
Return this. reshtml;
}

/// <Summary>
/// Load the verification code
/// </Summary>
/// <Returns> Verification Code image </returns>
Public System. Drawing. Image LoadPWDext ()
{
This. strUrl = "Verification Code URL ";
System. Drawing. Image img = null;
HttpWebRequest request = CreateRequest ();
HttpWebResponse response = null ;;
Try
{
Response = (HttpWebResponse) request. GetResponse ();
Img = System. Drawing. Image. FromStream (response. GetResponseStream (); // directly create an Image as stream.
// Obtain the cookie
If (response. Cookies. Count> 0)
{
This. _ cookieGet = response. Cookies;
}
}
Catch (System. Exception ex)
{
Console. WriteLine (ex. Message );
}
Return img;
}

# Region Constructor
Public HttpProc ()
{
}

/// <Summary>
/// Constructor
/// </Summary>
/// <Param name = "Address"> sent address </param>
/// <Param name = "cookie to be sent"> set of cookies to be sent </param>
Public HttpProc (string address, cookie to be sent by System. Net. CookieCollection)
{
This. _ strUrl = address;
This. _ cookiePost = cookie to be sent;
}

/// <Summary>
/// Constructor
/// </Summary>
/// <Param name = "Address"> sent address </param>
/// <Param name = "send data"> data to be sent </param>
Public HttpProc (string address, string sends data)
{
This. _ strUrl = address;
This. _ strPostdata = Send data;

}

/// <Summary>
/// Constructor
/// </Summary>
/// <Param name = "Address"> sent address </param>
Public HttpProc (string address)
{
This. _ strUrl = address;
}

/// <Summary>
/// Constructor
/// </Summary>
/// <Param name = "Address"> sent address </param>
/// <Param name = "send data"> data to be sent </param>
/// <Param name = "cookie to be sent"> set of cookies to be sent </param>
Public HttpProc (string address, string sending data, System. Net. CookieCollection cookie to be sent)
{
This. _ strUrl = address;
This. _ strPostdata = Send data;
This. _ cookiePost = cookie to be sent;
}
# Endregion

# Region address
Private string _ strUrl;
/// <Summary>
/// Request the http address
/// </Summary>
Public string strUrl
{
Get
{
Return _ strUrl;
}
Set
{
_ StrUrl = value;
}
}
# Endregion

# Region Source Address
Private string _ strRefUrl;
/// <Summary>
/// Reference address of the current page
/// </Summary>
Public String strrefurl
{
Get
{
Return _ strrefurl;
}
Set
{
_ StrRefUrl = value;
}
}
# Endregion

# Region data
Private string _ strPostdata;
/// <Summary>
/// Sent data
/// </Summary>
Public string strPostdata
{
Get {return this. _ strPostdata ;}
Set {this. _ strPostdata = value ;}
}
# Endregion

# Set of cookies to be sent by region
Private System. Net. CookieCollection _ cookiePost;
/// <Summary>
/// Set of sent cookies
/// </Summary>
Public System. Net. CookieCollection cookiePost
{
Get
{
Return _ cookiePost;
}
Set {_ cookiePost = value ;}
}
# Endregion

# Set of cookies obtained by region
Private System. Net. CookieCollection _ cookieGet;
/// <Summary>
/// Set of sent cookies
/// </Summary>
Public System. Net. CookieCollection cookieGet
{
Get
{
Return _ cookieget;
}
}
# Endregion

# Region proxy

Private system. net. iwebproxy _ proxy;
/// <Summary>
/// Proxy Server
/// </Summary>
Public System. net. iwebproxy proxy
{
Get {return this. _ proxy ;}
Set {This. _ proxy = value ;}
}
# Endregion

# Whether region is successfully sent
Private bool _ succeed;
/// <Summary>
/// Whether the execution is successful
/// </Summary>
Public bool succeed
{
Get {return _ succeed ;}
Set {_ succeed = value ;}
}
# Endregion

# Region response html results
Private string _ ResHtml;
/// <Summary>
/// Returned html result, in text format
/// </Summary>
Public string ResHtml
{
Get
{

Return _ ResHtml;


}
}
# Endregion

# Region response code
Private string _ strCode;
/// <Summary>
/// Response code
/// </Summary>
Public string strCode
{
Get {return _ strCode ;}
Set {_ strCode = value ;}
}
# Endregion

# Region error text
Private string _ strErr;
/// <Summary>
/// Error text
/// </Summary>
Public string strErr
{
Get {return _ strErr ;}
Set {_ strErr = value ;}
}
# Endregion

# Region encoding
Private System. Text. Encoding _ encoding = System. Text. Encoding. Default;
Public System. Text. Encoding encoding
{
Get {return _ encoding ;}
Set {_ encoding = value ;}
}
# Endregion

}
}

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.