2016-10-26 43 views
0

我创建了一个项目:如何导入HTTPotion成灵药项目

$ mix new sample 

我编辑的mix.exs文件:

defmodule Sample.Mixfile do 
    use Mix.Project 

    def project do 
    [app: :sample, 
    version: "0.1.0", 
    elixir: "~> 1.3", 
    build_embedded: Mix.env == :prod, 
    start_permanent: Mix.env == :prod, 
    deps: deps()] 
    end 

    def application do 
    [applications: [:logger, :httpotion]] 
    end 

    defp deps do 
    [{:httpotion, "~> 3.0.2"}] 
    end 
end 

和我samplex.ex文件:

defmodule Sample do 
    IO.puts "Hello World" 
end 

我运行:

$ mix deps.get 
$ mix 

,我也得到:

Compiling 1 file (.ex) 
Hello World 
Generated sample app 

直到这里都完美的,但是如果我改变sample.ex到:

defmodule Sample do 
    HTTPotion.get "httpbin.org/get" 
end 

我得到以下错误:

$ mix deps.get 
Running dependency resolution 
All dependencies up to date 
$ mix   
Compiling 1 file (.ex) 
warning: variable response is unused 
    lib/sample.ex:2 


== Compilation error on file lib/sample.ex == 
** (ArgumentError) argument error 
    (stdlib) :ets.lookup(:ibrowse_lb, {'httpbin.org', 80}) 
    /Users/xxx/sample/deps/ibrowse/src/ibrowse.erl:328: :ibrowse.send_req/6 
    lib/httpotion.ex:355: HTTPotion.request/3 
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6 

什么不见​​了?我没有灵丹妙药的经验。

+0

尝试在'mix.exs'中的'applications'中添加':httpotion':'[applications:[:logger,:httpotion]]''。 – Dogbert

+0

谢谢@Dogbert我更新了这个问题,但错误是一样的 – ademar111190

回答

1

我已经使用提供的步骤重现了该问题。 HTTPotion.get/2如果直接在模块 中调用,会引发异常,但如果从函数调用,则工作正常。

defmodule Sample do 
    def request do 
    HTTPotion.get "httpbin.org/get" 
    end 
end 

经过与测试

defmodule SampleTest do 
    use ExUnit.Case 

    test "response from HTTPotion" do 
    assert Sample.request 
    end 
end 

我认为它会引发异常,如果调用编译时间。