1

我正在制作一个 Windows Phone 8 应用程序。我有目标位置的纬度和经度。我需要获取目标位置的两个字母 ISO 国家代码。

我正在使用以下代码来实现它。

        'Dim address As String = puri
        'Dim client As WebClient = New WebClient()
        'Dim reader As StreamReader = New StreamReader(address)
        'code = reader.ReadToEnd
        Dim inStream As StreamReader
        Dim wr As WebRequest
        Dim webresponse As WebResponse
        wr = WebRequest.Create(puri)
        webresponse = wr.GetResponse()
        inStream = New StreamReader(webresponse.GetResponseStream())
        code = inStream.ReadToEnd()

其中 puri(在注释代码中)是字符串格式的 Web 服务的地址。

尝试注释代码时,我得到的错误是字符串无法转换为 system.uri 格式。(地址)

尝试未注释的代码时,我收到一条错误消息,指出 getresponse 不是类 system.net.webrequest() 的成员

我猜随着 .NET 的更新代码发生了变化,但我找不到任何关于该主题的最新信息。

URI = http://api.geonames.org/countryCode?lat=17.60890&lng=76.98966&username=demo
4

1 回答 1

-1

我认为您应该使用WebClient 类而不是 WebRequest。它更简单,更快。这是一个简单的例子:

Dim WebCL As New WebClient
Dim DownLoadedText As String = String.Empty
Try
    DownLoadedText = WebCL.DownloadString("Your Url")
    ' Do something 
Catch ex As Exception
    Throw New Exception("Oops!! ERROR has occured, something is wrong with your address")
End Try
于 2014-09-03T17:31:08.657 回答