我从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}]}}
我需要有关如何成功完成该请求的建议。
答案 0 :(得分: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
用户指南说:
以下调用使用默认客户端配置文件。使用代理 &#34; www-proxy.mycompany.com:8000&#34;,除了对localhost的请求。 这适用于以下所有请求。
这对我来说很有意义:
在tincidunt diam的Maecenas。在orci sed dolor vullenate的Pellentesque tincidunt。 Etiam malesuada finibus nisi。 Lorem ipsum dolor sit amet, 奉献精神。
要停止客户,请执行以下操作:
inets:stop()
编辑:我必须弄清楚如何停止服务器,因为我在此代码中执行了此操作: