2014-08-29 33 views
1

我得到一个noproc异常,当我尝试调用httpc:request(get, ...)geturl/1功能二郎异常错误:未定义功能lhttpc:启动/ 0

** exception exit: {noproc,{gen_server,call, 
            [httpc_manager, 
            {request,{request,undefined,<0.54.0>,0,http, 

为了解决这个问题,我把在start电话https://stackoverflow.com/a/14553219/58129

testurl() -> 
    ssl:start(), 
    lhttpc:start(), 
    geturl("http://www.cnn.com"). 

它失败,此错误:

根据这个答案我
so1:testurl(). 
** exception error: undefined function lhttpc:start/0 
    in function so1:testurl/0 (so1.erl, line 7) 

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

+1

lhttpc不是Erlang分布的一部分,如果你想使用它,你需要从[https://github.com/esl/lhttpc下载](https://github.com/esl/lhttpc)并将其放入VM路径中。 – Pascal 2014-08-29 07:12:13

+0

@帕斯卡尔谢谢! – 2014-08-29 07:16:49

回答

5

在文档的httpc,你可以阅读:

When starting the Inets application a manager process for the default profile will be started. The functions in this API that do not explicitly use a profile will access the default profile. A profile keeps track of proxy options, cookies and other options that can be applied to more than one request.

If the scheme https is used the ssl application needs to be started. When https links needs to go through a proxy the CONNECT method extension to HTTP-1.1 is used to establish a tunnel and then the connection is upgraded to TLS, however "TLS upgrade" according to RFC 2817 is not supported.

Also note that pipelining will only be used if the pipeline timeout is set, otherwise persistent connections without pipelining will be used e.i. the client always waits for the previous response before sending the next request.

简单:你必须开始inets:

application:start(inets). 

,这是足以让非SSL连接。对于HTTPS connecitons,你也需要启动:

application:start(crypto), 
application:start(public_key), 
application:start(ssl), 
application:start(inets). 
+0

感谢您的配额。 – 2015-03-21 14:54:26