您的位置:首页 > 理论基础 > 计算机网络

使用HttpWebRequest提交表单数据

2007-10-16 13:21 316 查看

'本程序仅供参考,请勿用于非法用途


Dim strId As String = "lishewen"


Dim strPassword As String = "123456"




'定义编码器


Dim encoding As New ASCIIEncoding()




Dim postData As String = "userid=" + strId


postData += ("&password=" + strPassword)




Dim data As Byte() = encoding.GetBytes(postData)




'获得HttpWebRequest对象


Dim myRequest As HttpWebRequest = DirectCast(WebRequest.Create("http://www.lishewen.com/login.asp"), HttpWebRequest)




myRequest.Method = "POST"


myRequest.ContentType = "application/x-www-form-urlencoded"


myRequest.ContentLength = data.Length


Dim newStream As Stream = myRequest.GetRequestStream()




'发送数据


newStream.Write(data, 0, data.Length)


newStream.Close()




'接收返回信息


Dim myResponse As HttpWebResponse = DirectCast(myRequest.GetResponse(), HttpWebResponse)


Dim reader As New StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.[Default])


Dim content As String = reader.ReadToEnd()


Console.WriteLine(content)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: