1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

value of type string cannot be converted to system.uri

Discussion in 'Visual Basic .NET' started by fpforum, Dec 28, 2012.

  1. fpforum

    fpforum Junior Member

    Joined:
    Apr 22, 2008
    Messages:
    117
    Likes Received:
    4
    Home Page:
    Hey everyone..I am trying to make a small HTTP proxy checker and I've found a pretty nice function online that will do just that. However, the function must be called like this:
    CheckProxy("http://proxy : port") ----minus the spaces

    In my listbox I have the proxies entered only in proxy:port format.

    I'm trying to add the http:// portion to it by using the following code

    Code:
    CheckProxy("http://" & "lstProxiesToTest.SelectedItem")
    
    This gives me an exception of..value of type string cannot be converted to system.uri

    any idea how to fix this and append http:// before it adds the proxy ip and port?


    Thanks!
     
  2. Psychop1

    Psychop1 Registered Member

    Joined:
    Jul 30, 2010
    Messages:
    63
    Likes Received:
    19
    What is it you are trying to do exactly? Are you using the webbrowser control? Webbrowser control wouldn't be very efficient for something like this. I would suggest httpwebrequest.

    Nonetheless, if you have copied and pasted that, then you need to remove the quotes around "lstProxiesToTest.SelectedItem". Any time you are doing something like this and you run into a wall, try passing your values off to a msgbox first. That way you can validate that you are passing off the correct values.
     
    • Thanks Thanks x 1
    Last edited: Dec 28, 2012
  3. fpforum

    fpforum Junior Member

    Joined:
    Apr 22, 2008
    Messages:
    117
    Likes Received:
    4
    Home Page:
    Thanks for your response! Removing the quotes got rid of the exception and I'm going to test now..As for testing the actual proxies - I'm using a free function I found online using System.Net.Sockets ...It doesn't use a webbrowser control.

    ------

    Update: Although that seamed to remove the squiggly line I was getting before..I'm getting a different exception error when I actually run the program..Now I'm getting Unable to cast object of type 'System.String' to type 'System.Uri'. in the same location
    Code:
    ProxyStatus = CheckProxy("http://" & lstProxiesToTest.SelectedItem)
    
     
    Last edited: Dec 28, 2012
  4. fpforum

    fpforum Junior Member

    Joined:
    Apr 22, 2008
    Messages:
    117
    Likes Received:
    4
    Home Page:
    I was able to get this working by doing this..

    Dim proxyLink As String = "http://" & lstProxiesToTest.SelectedItem

    CheckProxy(New Uri(proxyLink))
     
  5. HatIsBlack

    HatIsBlack Regular Member

    Joined:
    Sep 17, 2010
    Messages:
    265
    Likes Received:
    187
    Location:
    Where i belong
    Since you have not shown the code to the CheckProxy() function it's not possible to say what is wrong. How do you test the Proxy inside that function.