使用HttpRequest向某网页发送Post请求
2004-08-10 17:29
555 查看
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();
}
{
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();
}
相关文章推荐
- 使用HttpWebRequest发送自定义POST请求
- 使用HttpWebRequest发送自定义POST请求(以http方式推送消息)
- 使用HttpWebRequest发送自定义POST请求(转帖)
- 使用HttpWebRequest发送自定义POST请求
- 使用 HttpWebRequest 发送模拟 POST 请求
- 使用HttpWebRequest发送自定义POST请求
- 使用HttpWebRequest发送自定义POST请求
- 使用HttpWebRequest发送自定义POST请求
- C# 后台使用HttpWebRequest发送POST请求帮助类
- 使用JavaScript的XMLHttpRequest发送POST、GET请求以及接收返回值
- wp7使用POST请求Asp.net网页时,HttpWebRequest的BeginGetResponse方法抛出NotSupportException异常的解决方法
- 使用HttpWebRequest发送自定义POST请求
- 使用JavaScript的XMLHttpRequest发送POST、GET请求以及接收返回值
- 使用HttpWebRequest发送自定义POST请求
- [导入]C#实现通过HttpWebRequest发送POST请求实现网站自动登陆
- 如何使用SOCKET 发送HTTP1.1 GET POST请求包
- 通过HttpWebRequest 发送 POST 请求实现自动登陆
- 使用HttpWebRequest发送HTTP请求,同时支持GET/POST方式提交。
- 通过HttpWebRequest 发送 POST 请求实现自动登陆
- C#实现通过HttpWebRequest发送POST请求实现网站自动登陆