how to make httpwebrequest via Tor

10,043

@junior-mayhe 's answer did it for me here

using Tor as Proxy

just in case anybody else stumbles across this question in the future...

junior-mayhe: if you see this, will you please answer here, so i can up my rep a bit? thanks :-)

Share:
10,043
Yisroel M. Olewski
Author by

Yisroel M. Olewski

Updated on June 17, 2022

Comments

  • Yisroel M. Olewski
    Yisroel M. Olewski almost 2 years

    im trying to make a request via the tor proxy

    myRequest.Proxy = New WebProxy("127.0.0.1", 8118)
    

    but this gives me an error Unable to connect to the remote server

    and the inner exception is No connection could be made because the target machine actively refused it 127.0.0.1:8118

    my reading shows this might be a firewall issue, so i turned off windows FW entirely, i also temporarily disabled my AVG AV. i don't have any other protections that im aware of

    for good measure i also tried 9050 & 9051 as port numbers but that didn't help

    the Tor browser is working, so i guess my code should work as well. how do i set the proxy to use Tor.

    BTW, the "8118" is out of memory, i couldn't find any documentation as to which port i should use as the proxy

    maybe my tor is set to something else?

    thanks a million!

    EDIT

    regarding privoxy:

    in the past (about a year ago or more) i just download tor, and then added 8118 as the proxy and all worked. now it doesn't. maybe something changed?

    so i downloaded now privoxy as suggested by CodeCaster, now when both tor and privoxy are running, then the requests work, but, im afraid its not utilizing the tor proxy, as the responses are coming back as if im recognized by the server

    do you know maybe why in the past i did not have to download privoxy, and now it must be downloaded and enabled?

    thank you

    EDIT #2: Testing

    i made now a simple test function like so:

        Function ExternalIP(Optional Proxy As Integer? = Nothing) As String
            Dim webClient = New WebClient
            webClient.Headers.Add("Cache-Control", "max-age=0")
            If Proxy.HasValue Then webClient.Proxy = New WebProxy("127.0.0.1", Proxy.Value)
            Dim ip = webClient.DownloadString("http://myip.ozymo.com/")
            webClient.Dispose()
            Return ip
        End Function
    

    when used without passing a proxy, i get back my regular real ip. so far so good

    when i use 8118 as the proxy, then it depends:

    if privoxy is running then i get back my regular ip, (instead of the spoofed one which appears in the tor browser). which makes the whole thing pointless

    if its not running then i get the the above error No connection could be made because the target machine actively refused it 127.0.0.1:8118

    just to recap, in the past ive used Tor itself (plus Vidalia) without Privoxy or anything like that, and it worked just fine.

    thank you