erlang异常错误:未定义函数lhttpc:start/0

Ant*_*ong 2 erlang

我得到一个noproc例外,当我尝试调用httpc:request(get, ...)一个geturl/1函数

** exception exit: {noproc,{gen_server,call,
                                   [httpc_manager,
                                    {request,{request,undefined,<0.54.0>,0,http,
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,starttesturl/0根据这个答案接听了我的电话:https: //stackoverflow.com/a/14553219/58129

testurl() ->
    ssl:start(),
    lhttpc:start(),
    geturl("http://www.cnn.com").
Run Code Online (Sandbox Code Playgroud)

它失败并出现此错误:

so1:testurl().
** exception error: undefined function lhttpc:start/0
     in function  so1:testurl/0 (so1.erl, line 7)
Run Code Online (Sandbox Code Playgroud)

我谷歌,我找不到一个称为的模块lhttpc.什么是正确的httpc:request工作方式?

tko*_*wal 6

在httpc的文档中,您可以阅读:

启动Inets应用程序时,将启动默认配置文件的管理器进程.此API中未明确使用配置文件的功能将访问默认配置文件.配置文件会跟踪可应用于多个请求的代理选项,Cookie和其他选项.

如果使用方案https,则需要启动ssl应用程序.当https链接需要通过代理时,使用对HTTP-1.1的CONNECT方法扩展来建立隧道,然后将连接升级到TLS,但是不支持根据RFC 2817的"TLS升级".

另请注意,仅在设置管道超时时才使用流水线操作,否则将使用没有流水线操作的持久连接,即客户端在发送下一个请求之前始终等待先前的响应.

简而言之:你必须启动inets:

application:start(inets).
Run Code Online (Sandbox Code Playgroud)

这对于非ssl连接就足够了.对于https连接,您还需要启动:

application:start(crypto),
application:start(public_key),
application:start(ssl),
application:start(inets).
Run Code Online (Sandbox Code Playgroud)