The remote submission form and irrigation process are simple. If the message board has a verification code, it will be over.
Core code block
String url = "http: // localhost: 3359/web/message. aspx ";
# Region // accept the returned page
// Method 1
// Httpwebrequest request = webrequest. Create (URL) as httpwebrequest;
// Request. method = "get ";
// Request. keepalive = false;
// Httpwebresponse response = request. getresponse () as httpwebresponse;
// Stream = response. getresponsestream ();
// Streamreader reader = new streamreader (stream, encoding. utf8 );
// String srcstring = reader. readtoend ();
// Method 2
WebClient = new WebClient ();
Byte [] responsebytes = WebClient. downloaddata (URL );
String srcstring = encoding. utf8.getstring (responsebytes );
# Endregion
// Obtain the veiwstate of the page
String regviewstate = "<input type = \" Hidden \ "name = \" _ viewstate \ "id = \" _ viewstate \ "value = \"(? <Viewstate> [^ \ s \ t \ r \ n \ "\" '<>] *) \ "/> ";
Match mathview = RegEx. Match (srcstring, regviewstate, regexoptions. ignorecase | regexoptions. multiline );
String viewstate = mathview. Groups [1]. value;
// Obtain eventvalidation of the page
String regevent = "<input type = \" Hidden \ "name = \" _ eventvalidation \ "id = \" _ eventvalidation \ "value = \"(? <Viewstate> [^ \ s \ t \ r \ n \ "\" '<>] *) \ "/> ";
Match matchevent = RegEx. Match (srcstring, regevent, regexoptions. ignorecase | regexoptions. multiline );
String eventvalidation = matchevent. Groups [1]. value;
// Automatically submit
String submitbutton = "message ";
String txttitle = this.txt content. Text; // Title
String txtcontent = this.txt title. Text; // message content
// Convert the text into a URL encoded string
Viewstate = system. Web. httputility. urlencode (viewstate );
Eventvalidation = system. Web. httputility. urlencode (eventvalidation );
Submitbutton = system. Web. httputility. urlencode (submitbutton );
// String data to be submitted. Format: User = uesr1 & Password = 123
String poststring = string. format ("txttitle = {0} & txtcontent = {1}" + "& btnsave =" + submitbutton + "& __ viewstate =" + viewstate + "& __ eventvalidation =" + eventvalidation, txttitle, txtcontent );
Byte [] postdata = encoding. utf8.getbytes (poststring); // converts a string to a byte array
// Submit cyclically
Int num = convert. toint32 (txtnum. Text );
For (INT I = 0; I <= num; I ++)
{
WebClient = new WebClient ();
WebClient. headers. Add ("Content-Type", "application/X-WWW-form-urlencoded ");
WebClient. uploaddata (URL, "Post", postdata); // uploads data and returns the byte array of the page.
}
Clientscriptmanager cs = page. clientscript;
CS. registerclientscriptblock (typeof (PAGE), "", "<SCRIPT> alert ('execution completed '); </SCRIPT> ");
Download source file