VB.net 带Cookie POST
调用方法 CookiePost(POST网址,POST地址,Cookie)
Public Function CookiePost(ByVal Post_Url As String, ByVal Post_Data As String, ByVal PostCookie As String) As String '带Cookie Post函数
System.Net.ServicePointManager.Expect100Continue = False
Dim request As WebRequest = Net.WebRequest.Create(Post_Url)
request.Method = "POST"
Dim postData As String = Post_Data
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
request.ContentType = "application/x-www-form-urlencoded"
request.Headers.Add("Cookie:" + PostCookie)
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As WebResponse = request.GetResponse()
Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
Console.WriteLine(responseFromServer)
CookiePost = responseFromServer
reader.Close()
dataStream.Close()
response.Close()
End Function