cmullaparthi / ibrowse

Erlang HTTP client
Other
515 stars 191 forks source link

Socks5 not working for post requests? #141

Closed vans163 closed 8 years ago

vans163 commented 8 years ago

The very last example which shows using socks5 with get request is not working, I am trying a post request and it is not using the proxy.

cmullaparthi commented 8 years ago

Are you using a SOCKS server and is it running when you invoke the request?

vans163 commented 8 years ago

Im invoking the request to a http server thats turned off?? There is nothing in the code that makes it fall into the clause to use the socks5 proxy. If you pass it proxy_host it will fall into the clause to use HTTP proxy. It seems on previous releases socks5 works for the http get/post requests, but the master branch is broken for some reason.

cmullaparthi commented 8 years ago

See https://github.com/cmullaparthi/ibrowse/blob/master/src/ibrowse_http_client.erl#L570

Can you post the exact format of the request you are using please?

vans163 commented 8 years ago
PostData = <<"igotsomestuff">>,
PostUrl = "https://service.asite.com",
Options =
            [
            {socks5_host, "1.1.1.1"},
            {socks5_port, 4444},
            {connect_timeout, 20000}, 
            {inactivity_timeout, 20000}
        ],
{ok, "201", Headers, Body} = ibrowse:send_req(PostUrl, [], post, PostData, Options, 20000),

It does not hit that clause on the latest release, it goes into

do_connect(Host, Port, Options, #state{is_ssl      = true,
                                       use_proxy   = false,
                                       ssl_options = SSLOptions},
           Timeout) ->
    ssl:connect(Host, Port, get_sock_options(Host, Options, SSLOptions), Timeout);

Always

cmullaparthi commented 8 years ago

Just pushed a fix to master.

9> Options = [{socks5_host, "localhost"}, {socks5_port, 2001}].    
[{socks5_host,"localhost"},{socks5_port,2001}]

10> ibrowse:send_req("http://www.google.com", [], get, [], Options).
{ok,"302",
    [{"Cache-Control","private"},
     {"Content-Type","text/html; charset=UTF-8"},
     {"Location",
      "http://www.google.co.uk/?gfe_rd=cr&ei=iDyuVuy1BfLH8geBuaPwAg"},
     {"Content-Length","261"},
     {"Date","Sun, 31 Jan 2016 16:55:36 GMT"},
     {"Server","GFE/2.0"}],
    "<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n<TITLE>302 Moved</TITLE></HEAD><BODY>\n<H1>302 Moved</H1>\nThe document has moved\n<A HREF=\"http://www.google.co.uk/?gfe_rd=cr&amp;ei=iDyuVuy1BfLH8geBuaPwAg\">here</A>.\r\n</BODY></HTML>\r\n"}