ccc125l87l92l206cad32
fy53999
飞快的心情fy53999

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

posted on 2019-11-05 23:12  fy53999  阅读(79)  评论(0编辑  收藏  举报