使用HttpWebRequest无需注销的POST&GET第二页

时间:2019-06-17 17:40:29

标签: vb.net

我在页面上,我在/index.html中执行一个简单的帖子请求, 现在,当我执行“获取请求”以查看/documents.html时 它说我需要再次登录才能使用HttpWebRequest修复该问题。

POST请求, 提出要求, 没有工作。要求我登录。

        'POST REQ
        Dim Request As HttpWebRequest = CType(WebRequest.Create("https://example.com/login.php"), HttpWebRequest)
        Request.Method = "POST"
        Request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"
        Dim POST As String = "emailAddress=" + email + "&password=" + pass + ""
        Dim byteArray() As Byte = Encoding.UTF8.GetBytes(POST)
        Request.ContentLength = byteArray.Length
        Dim DataStream As Stream = Request.GetRequestStream()
        DataStream.Write(byteArray, 0, byteArray.Length)
        DataStream.Close()
        Dim Response As HttpWebResponse = Request.GetResponse()
        DataStream = Response.GetResponseStream()
        Dim reader As New StreamReader(DataStream)
        Dim ServerResponse As String = reader.ReadToEnd()
        reader.Close()
        DataStream.Close()
        Response.Close()
        'END POST REQ
        If ServerResponse.Contains("validation") Then
            Console.ForegroundColor = ConsoleColor.Red
            Console.WriteLine("Bad")
        Else
            Console.ForegroundColor = ConsoleColor.Green
            Console.WriteLine("Good")
            'GET REQ
                Dim requestUrl_ As String = "https://example.com/document.php"
                Dim request_ As HttpWebRequest = TryCast(WebRequest.Create(requestUrl_), HttpWebRequest)
                Dim response_ As HttpWebResponse = TryCast(request_.GetResponse(), HttpWebResponse)
                Dim dataStream_ As Stream = response_.GetResponseStream()
                Dim reader_ As New StreamReader(dataStream_)
                Dim responseFromServer_ As String = reader_.ReadToEnd()
                Dim result_ = responseFromServer_
                reader_.Close()
                response_.Close()
                if result_.contains("BestellDatum:") then
                console.writeline("Success")
                else
                console.writeline("Rip")
                end if
            'END GET REQ
        End If

如果有人可以帮助我,我会很高兴。试图找到一个解决方案大约一年,我不是在撒谎,我做不到这么长时间。

0 个答案:

没有答案