winForm 如何向 webForm 提交数据
这样试一下:
方法:
Public Function PostDate()Function PostDate(ByVal url As String, ByVal PostData() As String) As String
Dim Post As String = ""
For Each s As String In PostData
Post += s + "&"
Next
Post = Post.Substring(0, Post.Length - 1)
Dim html As String = ""
Dim encoding As Encoding = encoding.GetEncoding("GB2312")
Dim data As Byte() = encoding.GetBytes(Post)
Dim myRequest As HttpWebRequest = CType(WebRequest.Create(url), 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 resp As HttpWebResponse = CType(myRequest.GetResponse(), HttpWebResponse)
Dim sr As StreamReader = New StreamReader(resp.GetResponseStream(), System.Text.Encoding.Default)
html = sr.ReadToEnd()
Return html
End Function
调用:
Dim postdata As String() = {"id=luajiu", "pw=xxxx", "ipmask=0"}
Dim strUrl As String = "http://bbs.cau.edu.cn/wusetu.cn/bbslogin"
Dim SessionHtml As String = PostDate(strUrl, postdata)