2014-08-29 31 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