【问题标题】:System.Net.WebException' occurred in System.dllSystem.Net.WebException'发生在 System.dll
【发布时间】:2018-02-06 01:37:36
【问题描述】:

完整的异常如下所示:

An exception of type 'System.Net.WebException' occurred in System.dll but was not handled in user code

Additional information: The remote server returned an error: (404) Not Found.

我的代码如下所示:

Public Function GetHash(password As String) As String Implements IHashManager.GetHash
        Dim uRL As String = HttpContext.Current.Request.Url.Scheme & "://" & HttpContext.Current.Request.Url.Host & ":" & HttpContext.Current.Request.Url.Port & "/md5_hash.asp?val=" & password

        ' Dim myWebClient As New Net.WebClient
        Using myWebClient As New Net.WebClient
            Return myWebClient.DownloadString(uRL)
        End Using
    End Function

它在返回线上抛出异常。

代码的目的是使用当前 URL 返回密码的哈希值。我没有编写此代码,我不确定它为什么会出错。有谁知道为什么?

【问题讨论】:

    标签: asp.net vb.net exception


    【解决方案1】:

    当您调用myWebClient.DownloadString() 时,您需要检查uRL 的值。 “附加信息”很清楚;您收到一个 404 错误,指出在 uRL 中标识的资源在该位置未找到/不存在。

    【讨论】:

    • 你也不应该使用你不理解的代码。
    • 感谢您的回复,这个问题的目的是为了更好地理解代码并解决问题。我尽量不使用我不懂的代码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-08
    • 1970-01-01
    相关资源
    最近更新 更多