如何从失败的webclient.downloadstring获得结果?

时间:2013-02-24 12:55:56

标签: vb.net

如果我们在服务器上使用webclient.downloadstring有错误,我们什么都没有

        Try
            result = webClient.DownloadString("https://api.bodis.com/domainclassification?domain=" + CurrentBlog.Domain)
        Catch ex As Exception
            System.Windows.Forms.Application.DoEvents()
        End Try

通常结果包含响应。但是如果错误结果是空的。

我想知道一些事情。例如,即使结果不好,通常也会有自定义404消息等。

api.bodis.com存在问题,因为它混合了安全和非安全的东西。但是,无论如何它都会在Internet Explorer中提供输出。我想使用webclient,我想知道输出

获得ex.response不会产生任何结果

        Dim adult = webClient.DownloadString("http://googleads.g.doubleclick.net/apps/domainpark/domainpark.cgi?callback=_google_json_callback&output=js&client=ca-dp-godaddy2_xml&domain_name=" + CurrentBlog.Domain)
        'ias.NavigateTillComplete("https://api.bodis.com/domainclassification?domain=" + CurrentBlog.Domain)
        Dim result = ""
        Dim url = "http://api.bodis.com/domainclassification?domain=" + CurrentBlog.Domain
        Dim webRequest = DirectCast(System.Net.HttpWebRequest.Create(url), System.Net.HttpWebRequest)
        Dim response As HttpWebResponse
        Try
            response = DirectCast(webRequest.GetResponse(), HttpWebResponse)
        Catch ex As System.Net.WebException
            System.Windows.Forms.Application.DoEvents()
            response = DirectCast(ex.Response, HttpWebResponse) 'is nothing there
        End Try

        Dim responseStream = response.GetResponseStream

0 个答案:

没有答案