【问题标题】:inets httpc: client example in User's Guide not workinginets httpc:用户指南中的客户端示例不起作用
【发布时间】:2018-08-25 05:56:20
【问题描述】:

我从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}]}}

我需要有关如何使该请求成功完成的建议。

【问题讨论】:

    标签: erlang inets


    【解决方案1】:

    这似乎有效:

    $ 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  
    

    用户指南说:

    以下调用使用默认客户端配置文件。使用代理 “www-proxy.mycompany.com:8000”,对 localhost 的请求除外。 这适用于以下所有请求。

    这对我来说很有意义:

    在 tincidunt 直径的 Maecenas。 Pellentesque in orci sed dolor vulputate 暂时的。 Etiam malesuada finibus nisi。 Lorem ipsum dolor sit amet, consectetur adipiscing 精英。

    要停止客户端,我只是这样做:

      inets:stop()
    

    ?

    编辑:我一定想出了如何停止服务器,因为我在这段代码中做到了:

    Erlang read post request

    【讨论】:

      猜你喜欢
      • 2013-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-09
      • 1970-01-01
      • 2011-09-18
      • 1970-01-01
      相关资源
      最近更新 更多