原创  使用HttpRequest向某网页发送Post请求 收藏

private void OnPostInfoClick(object sender, System.EventArgs e)
{
string strId = UserId_TextBox.Text;
string strName = Name_TextBox.Text;

ASCIIEncoding 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;
Stream newStream=myRequest.GetRequestStream();
// Send the data.
newStream.Write(data,0,data.Length);
newStream.Close();
}

发表于 @ 2004年08月10日 17:29:00 | 评论( loading... ) | 编辑| 举报| 收藏

旧一篇:使用DirectoryServices给文件添加访问权限 | 新一篇:如何遍历显示一个枚举的内容

  • 发表评论
  • 评论内容:
  •  
Copyright © acewang
Powered by CSDN Blog