inets httpc:用户指南中的客户端示例不起作用 [英] inets httpc: client example in User's Guide not working

查看:128
本文介绍了inets httpc:用户指南中的客户端示例不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 inets用户指南中复制了以下代码:

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.

推荐答案

这似乎可行:

$ 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",但从本地主机发出的请求除外. 这适用于以下所有请求.

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.

这对我来说意义十足:

蒂西多姆直径的梅塞纳斯(Maecenas).腹痛性腹膜炎的腹腔穿刺 Tincidunt. Etiam malesuada finibus nisi. Lorem ipsum dolor坐在amet, 奉献的精英人士.

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()

?

我一定已经弄清楚了如何停止服务器,因为我是在以下代码中完成的:

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

Erlang阅读帖子请求

这篇关于inets httpc:用户指南中的客户端示例不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆