Send a POST request to a web page using httpRequest

xiaoxiao2021-03-06  201

Private Void OnPostInfoclick (Object Sender, System.EventArgs E)

{

String strid = userid_textbox.text;

String strname = name_textbox.text;

ASCIENCODING Encoding = new asciiencoding ();

String postData = "userid =" strid;

PostData = ("& UserName =" Strname);

Byte [] data = encoding.getbytes (postData);

// Prepare Web Request ...

HttpWebRequest myrequest = (httpwebrequest) WebRequest.create ("http://localhost/webapplication1/default.aspx");

MyRequest.Method = "post";

MyRequest.contentType = "Application / X-WWW-FORM-URLENCODED";

MyRequest.contentLength = data.length;

Street newstream = myRequest.getRequestStream ();

// dend the data.

Newstream.write (DATA, 0, DATA.LENGTH);

Newstream.close ();

}

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

New Post(0)