2013-02-24 114 views
-4
 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 = DirectCast(webRequest.GetResponse(), HttpWebResponse) 
     Dim responseStream = response.GetResponseStream 
     Dim responseString = responseStream.readAll? 'MethodAccessException doesn't exist 


     Dim responseString = responseStream.readAll? 'MethodAccessException doesn't exist 

我該如何替換Dim responseString = responseStream.readAll如何從流中讀取字符串

實際的命令是什麼?

+0

是什麼這個問題如此虛幻?有人給出了很好的答案。 – 2013-03-18 04:36:16

回答

1

您可以在響應流傳遞給StreamReader實例,然後使用ReadToEnd方法:

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) 
Using Dim response = DirectCast(webRequest.GetResponse(), HttpWebResponse) 
    Using Dim responseStream = response.GetResponseStream 
     Using Dim responseReader = new StreamReader(responseStream) 
      Dim responseString = responseReader.ReadToEnd() 
     End Using 
    End Using 
End Using 

但是爲什麼用HttpWebRequest的時候,你可以直接使用一個WebClient的麻煩:

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 responseString = webClient.DownloadString(url) 
+0

webclient有問題。 – 2013-02-24 14:29:45

+0

有什麼問題?我從來沒有遇到任何問題。 – 2013-02-24 14:32:15

+0

當下載字符串失敗時,根本無法獲得響應。 – 2013-02-25 01:37:30