0

私は以下を実行しようとしています:

Dim a As Boolean = False
        Try
            Dim myHTTPWebRequest As HttpWebRequest = CType(WebRequest.Create(txtToShorten.Text), HttpWebRequest)
            Dim myHTTPwebResponse As HttpWebResponse = CType(myHTTPWebRequest.GetResponse(), HttpWebResponse)
            If myHTTPwebResponse.StatusCode = HttpStatusCode.OK Then
                a = True
            End If
        Catch e As WebException
        Catch e As Exception
        End Try
        Return a

正しいURLを実行すると正常に動作し、trueを返しますが、入力されたURLが有効でない場合は値を返しません.

アイデアはありますか?

4

1 に答える 1

0

実際、これは私にとってはうまくいきます:

Imports System.Net

パブリック クラス Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim x As Boolean = bb()
    x = x

End Sub

Private Function bb() As Boolean

    Dim a As Boolean = False
    Try
        Dim myHTTPWebRequest As HttpWebRequest = CType(WebRequest.Create("http:\\www.fokikkkkkrd.com"), HttpWebRequest)
        Dim myHTTPwebResponse As HttpWebResponse = CType(myHTTPWebRequest.GetResponse(), HttpWebResponse)
        If myHTTPwebResponse.StatusCode = HttpStatusCode.OK Then
            a = True
        End If
    Catch ex As WebException
    Catch ex As Exception
    End Try
    Return a

End Function

クラス終了

このコードを関数内に入れましたか??

于 2013-03-29T15:12:13.513 に答える