Shared Sub postData()
Dim httpUrl As New System.Uri("http://sunhai.tianyablog.com?" & "name=yourName&pass=yourPass&cardnumber=yourCardNumber")
Dim req As HttpWebRequest
'req.Timeout = 10000 '设置超时值10秒
req = CType(WebRequest.Create(httpUrl2), HttpWebRequest)
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
Dim bytesData() As Byte = System.Text.Encoding.ASCII.GetBytes(""name=yourName&pass=yourPass&cardnumber=yourCardNumber")
req.ContentLength = bytesData.Length
Dim postStream As Stream = req.GetRequestStream()
postStream.Write(bytesData, 0, bytesData.Length) '以上向服务器post信息。
Dim res As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse) '以下获取服务器返回信息
Dim reader As StreamReader = _
New StreamReader(res.GetResponseStream, System.Text.Encoding.GetEncoding("GB2312"))
Dim respHTML As String = reader.ReadToEnd()
MsgBox(respHTML) '这就是向网络服务器post后返回的信息
MsgBox(res.StatusCode.ToString) '向网络服务器post后返回的状态码
res.Close() '关闭
End Sub
上面的代码,据网上的教程说是可以在网站上面自动发布内容的,但是为什么我用VS.NET2005编译上面这段网上代码的时候总是出错呢?请教各位大大,小弟菜菜鸟,如果可能请尽量用通俗一点的语言指教一下,另外可否把HttpWebRequest类的具体有法讲解一下!谢了!!!~