2011-11-19 150 views
-1

考慮以下代碼:我該如何解決這個錯誤?

Dim strUrl As String = "http://www.txtguru.in/imobile/api.php?username=username&password=password&source=senderid&dmobile=123456789012&message=message" 
Dim request As WebRequest = HttpWebRequest.Create(strUrl) 
Dim response As HttpWebResponse = DirectCast(request.EndGetResponse(), HttpWebResponse) 
Dim s As Stream = DirectCast(response.GetResponseStream(), Stream) 
Dim readStream As New StreamReader(s) 
Dim dataString As String = readStream.ReadToEnd() 
response.Close() 
s.Close() 
readStream.Close() 

我對request.EndGetResponse()得到一個錯誤和錯誤是:爲參數的「公共可重寫功能EndGetResponse(asyncResult作爲System.IAsyncResult 'asyncResult' 未指定

參數)作爲System.Net.WebResponse'。

我該如何解決?

回答

0

嘗試改變 -

Dim response As HttpWebResponse = DirectCast(request.EndGetResponse(), HttpWebResponse) 

Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse) 
2

您的意思是使用異步版本:

Dim response As HttpWebResponse = DirectCast(request.EndGetResponse(), HttpWebResponse) 

嘗試使用,而不是同步之一:

Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse) 
相關問題