减少http请求的超时等待

时间:2016-05-08 23:07:10

标签: .net vb.net

如何在vb.net中减少超时等待此请求?

Dim myip As String
    myip = IPLabel.Content

    Dim request As WebRequest = _
      WebRequest.Create("http://" + myip + "/web/remotecontrol?command=116")

    request.Credentials = CredentialCache.DefaultCredentials

    Try
        Dim response As WebResponse = request.GetResponse()


        Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)

        Dim dataStream As Stream = response.GetResponseStream()

        Dim reader As New StreamReader(dataStream)

        Dim responseFromServer As String = reader.ReadToEnd()

        Console.WriteLine(responseFromServer)


        reader.Close()
        response.Close()

    Catch ex As System.Exception
        MessageBox.Show("Error: " + ex.Message)


    End Try

如果我向当时无法访问的IP地址发出请求,则仅在20秒后抛出异常,我希望将该时间缩短为5秒或更短。

0 个答案:

没有答案