jason2li
Member
Hi, I am trying to extract a user's general location based on their IP address. I've found several programs that have an annual fee to accomplish this, but I dug a little deeper and found this:
http://ws.cdyne.com/ip2geo/ip2geo.asmx/ResolveIP?IPaddress=1.1.1.1&LicenseKey=0 (Change the "1.1.1.1" to a valid IP address)
Which is exactly what I need. It works when I browse to it in IE7. And it also works when I use the exact same code from a Windows application. But when I try to access that page programmatically from my ASP.NET page, it throws this error:
Here is my code:
Any ideas?
http://ws.cdyne.com/ip2geo/ip2geo.asmx/ResolveIP?IPaddress=1.1.1.1&LicenseKey=0 (Change the "1.1.1.1" to a valid IP address)
Which is exactly what I need. It works when I browse to it in IE7. And it also works when I use the exact same code from a Windows application. But when I try to access that page programmatically from my ASP.NET page, it throws this error:
VB.NET:
The remote server returned an error: (401) Unauthorized.
Here is my code:
VB.NET:
Private Function getGeographicalInformation(ByVal IPAddress As String) As String
Dim stringBuilder As New System.Text.StringBuilder("")
Dim request As WebRequest = WebRequest.Create("http://ws.cdyne.com/ip2geo/ip2geo.asmx/ResolveIP?IPaddress=" & IPAddress & "&LicenseKey=0")
Dim response As WebResponse = request.GetResponse() [COLOR="Red"]' The error is thrown here[/COLOR]
Dim iTotalBuff As Integer = 0
Dim Buffer(128) As [Byte]
Dim stream As System.IO.Stream = response.GetResponseStream()
iTotalBuff = stream.Read(Buffer, 0, 128)
While iTotalBuff <> 0
stringBuilder.Append(System.Text.Encoding.ASCII.GetString(Buffer, 0, iTotalBuff))
iTotalBuff = stream.Read(Buffer, 0, 128)
End While
Return stringBuilder.ToString.Trim
End Function
Any ideas?