erlanginets

inets httpc: client example in User's Guide not working


I copied the following code from the inets User's Guide:

$ erl
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V8.2  (abort with ^G)

1> inets:start().
ok

2> httpc:set_options([{proxy, {{"www-proxy.mycompany.com", 8000}, ["localhost"]}}]).
ok

3> {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} = httpc:request("http://www.erlang.org").
* exception error: no match of right hand side value 
                {error,
                    {failed_connect,
                        [{to_address,{"www-proxy.mycompany.com",8000}},
                         {inet,[inet],etimedout}]}}

I need advice on how to get that request to complete successfully.


Solution

  • This seems to work:

    $ erl
    Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
    
    Eshell V8.2  (abort with ^G)
    
    1> inets:start().
    ok
    
    2> {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} = httpc:request("http://www.erlang.org").
    {ok,{{"HTTP/1.1",200,"OK"},
         [{"connection","keep-alive"},
          {"date","Sun, 25 Feb 2018 13:44:59 GMT"},
          {"server","nginx"},
          {"vary","Accept-Encoding"},
          {"content-length","12816"},
          {"content-type","text/html; charset=UTF-8"}],
         "<!DOCTYPE html>\n<html>\n  <head>\n    <title>Erlang Programming Language</title>\n    <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"/>\n    <meta name=\"description\" content=\"Erlang Programming Language\"/>\n    <meta name=\"keywords\" content=\"erlang, functional, programming, fault-tolerant, distributed, multi-platform, portable, software, multi-core, smp, concurrency\"/>\n  
    

    The User's Guide says:

    The following calls use the default client profile. Use the proxy "www-proxy.mycompany.com:8000", except from requests to localhost. This applies to all the following requests.

    which makes as much sense to me as:

    Maecenas in tincidunt diam. Pellentesque in orci sed dolor vulputate tincidunt. Etiam malesuada finibus nisi. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

    To stop the client, do I just do:

      inets:stop()
    

    ?

    Edit: I must have figured out how to stop the server because I did it in this code:

    Erlang read post request