http Web请求登录失败 - 但用户名和密码正确

时间:2016-12-11 13:17:06

标签: vb.net authentication visual-studio-2015 httpwebrequest http-authentication

这是我使用http web请求将其签名到网站的代码 出了问题,它不是我的用户名和密码。我使用http实时标头来获取有关帖子消息的信息。当我尝试代码时,它会给我一个页面,好像它是用户名或密码错误。

    Imports System.Net
Imports System.Text
Imports System.IO
Public Class Form1
    Dim logincookie As CookieContainer

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim postdata As String = "username=myusername%40gmail.com&token=fec2af73418281b566fe86d6fc02980e&perslogin=Y&password=mypassword%40&tprefs1=&tprefs2=9yUXLS7QDJXD.1oiOS1.51CcYO"
        Dim tempCookies As New CookieContainer
        Dim encoding As New UTF8Encoding
        Dim byteData As Byte() = encoding.GetBytes(postdata)

        Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://secure.thewebsite.com/secure_login.html?ver=2&loc=en_US&r=http%3A%2F%2Fwww.thewebsite.com%2Fhome.html%3Fjli%3D1&uri=http%3A%2F%2Fwww.thewebsite.com"), HttpWebRequest)
        postReq.Method = "POST"
        postReq.KeepAlive = True
        postReq.CookieContainer = tempCookies
        postReq.ContentType = "application/x-www-form-urlencoded"
        postReq.Referer = "https://secure.thewebsite.com/secure_login.html?ver=2&loc=en_US&r=http%3A%2F%2Fwww.thewebsite.com%2Fhome.html%3Fjli%3D1&uri=http%3A%2F%2Fwww.thewebsite.com"
        postReq.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"
        postReq.ContentLength = byteData.Length
        Dim postreqstream As Stream = postReq.GetRequestStream()
        postreqstream.Write(byteData, 0, byteData.Length)
        postreqstream.Close()
        Dim postresponse As HttpWebResponse

        postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
        tempCookies.Add(postresponse.Cookies)
        logincookie = tempCookies
        Dim postreqreader As New StreamReader(postresponse.GetResponseStream())

        Dim thepage As String = postreqreader.ReadToEnd
        RichTextBox1.Text = thepage

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        WebBrowser1.DocumentText = RichTextBox1.Text
    End Sub
End class

这是我得到的回复:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <script type="text/javascript">
            window.parent.location.href ="https://secure.thewebsite.com/register.html?display=login";
        </script>
     </head>
     <body >
     </body>
</html>

知道出现什么问题会导致登录失败吗?

0 个答案:

没有答案