我该如何解决这个错误?

时间:2011-11-19 19:30:17

标签: asp.net vb.net

考虑以下代码:

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()收到错误,错误是:

  

没有为'Public Overridable Function EndGetResponse(asyncResult As System.IAsyncResult)的参数'asyncResult'指定参数As System.Net.WebResponse'。

我该如何解决?

2 个答案:

答案 0 :(得分:2)

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

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

请尝试使用同步代码:

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

答案 1 :(得分:0)

尝试更改 -

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

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