1. VB. NET code
Imports system. textimports system. netimports system. iopublic class uwantslogin private loginid as string = "spang" Private loginpass as string = "123456" Public sub new () dim encoding as new utf8encoding dim postdata as string = "username =" & loginid & "& Password =" & loginpass dim data () as byte = encoding. getbytes (postdata) 'Prepare Web Request dim request as httpwebrequest = ctype (webrequest. crea Te ("http://www5.uwants.com/logging.php? Action = login "), httpwebrequest) request. method = "Post" request. contenttype = "application/X-WWW-form-urlencoded" request. contentlength = data. length dim newstream as stream = request. getrequeststream () 'send the data newstream. write (data, 0, Data. length) newstream. close () 'Get response dim response as httpwebresponse = ctype (request. getresponse (), httpwebresponse) dim reader as streamreader = new streamreader (response. getresponsestream (), system. text. encoding. getencoding ("big5") dim content as string = reader. readtoend () end subend class
Ii. Visual C # code
Using Microsoft. visualBasic; using system. collections; using system. collections. generic; using system. data; using system. diagnostics; using system. text; using system. net; using system. io; public class uwantslogin {private string loginid = "spang"; private string loginpass = "123456"; Public uwantslogin () {utf8encoding encoding = new utf8encoding (); string postdata = "username =" + loginid + "& passwo RD = "+ loginpass; byte [] DATA = encoding. getbytes (postdata); // Prepare web requesthttpwebrequest request = (httpwebrequest) webrequest. Create (" http://www5.uwants.com/logging.php? Action = login "); Request. method = "Post"; request. contenttype = "application/X-WWW-form-urlencoded"; request. contentlength = data. length; stream newstream = request. getrequeststream (); // send the datanewstream. write (data, 0, Data. length); newstream. close (); // get responsehttpwebresponse response = (httpwebresponse) request. getresponse (); streamreader reader = new streamreader (response. getresponsestream (), system. text. encoding. getencoding ("big5"); string content = reader. readtoend ();}}