System.dll中出现未处理的“System.Net.WebException”类型异常 - (Visual Basic)

时间:2016-08-07 00:47:20

标签: mysql vb.net encoding login

所以我正在使用本教程: http://www.mpgh.net/forum/showthread.php?t=442302

这是我唯一能找到的php登录系统,一切顺利,直到我按下“登录”按钮时出现此错误:

An unhandled exception of type 'System.Net.WebException' occurred in System.dll

我已经尝试修复它,但我对此非常无能为力,如果可能的话,我会很感激帮助:)

以下是整个代码:

Imports System.Net
Imports System.Text
Imports System.Web
Public Class login
    Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Process.Start("http://website.co.uk")
    End Sub
    Function CheckUser(AuthenticationPage As String, Username As String, Serial As String) As Boolean
        Dim wc As New WebClient()
        wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
        Dim Data As String = String.Format("username={0}&serial={1}", HttpUtility.UrlEncode(Username), HttpUtility.UrlEncode(Serial))
        Dim ResponseBytes() As Byte = wc.UploadData(AuthenticationPage, "POST", Encoding.ASCII.GetBytes(Data))
        Dim Response As String = Encoding.ASCII.GetString(ResponseBytes)
        If Response.Contains("Correct") Then
            Return True
        Else
            Return False
        End If
    End Function
    Function AddUser(StoragePage As String, Username As String, Serial As String) As Boolean
        Dim wc As New WebClient()
        wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
        Dim Data As String = String.Format("username={0}&serial={1}", HttpUtility.UrlEncode(Username), HttpUtility.UrlEncode(Serial))
        Dim ResponseBytes() As Byte = wc.UploadData(StoragePage, "POST", Encoding.ASCII.GetBytes(Data))
        Dim Response As String = Encoding.ASCII.GetString(ResponseBytes)
        If Response.Contains("User added") Then
            Return True
        Else
            Return False
        End If
    End Function
    Function DeleteUser(DeletionPage As String, Username As String, Serial As String) As Boolean
        Dim wc As New WebClient()
        wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
        Dim Data As String = String.Format("username={0}&serial={1}", HttpUtility.UrlEncode(Username), HttpUtility.UrlEncode(Serial))
        Dim ResponseBytes() As Byte = wc.UploadData(DeletionPage, "POST", Encoding.ASCII.GetBytes(Data))
        Dim Response As String = Encoding.ASCII.GetString(ResponseBytes)
        If Response.Contains("User deleted") Then
            Return True
        Else
            Return False
        End If
    End Function

    Private Sub FlatButton1_Click(sender As Object, e As EventArgs) Handles FlatButton1.Click
        If CheckUser("http://website.co.uk/cauth/load.php", login_username.Text, login_password.Text) Then
            'Do whatever you want to do on successful login here.
            MsgBox("You have successfully logged in.")
        Else
            'Do whatever you want to do on un-successful login here.
            MsgBox("You have provided invalid username or password. Unable to login.")
        End If
    End Sub
End Class

0 个答案:

没有答案