httprc:request抛出异常退出:{noproc,{gen_server,call,[httpc_manager ...]}}

时间:2017-11-12 16:44:21

标签: erlang httpc

我想在我的erlang程序中调用httprc:request,但我得到一个异常,它没有任何信息给我,出了什么问题。

这是我的代码:

print_helloworld() ->
  Body = "userId=12345",
  httpc:request(post,
    {
    "'http://192.168.2.100:8080/010/xmppcontrol", [],
      "application/x-www-form-urlencoded",
      Body
    }, [], []).

这是我的例外:

1> hello_world:print_helloworld().
** exception exit: {noproc,
                    {gen_server,call,
                     [httpc_manager,
                      {request,
                       {request,undefined,<0.58.0>,0,'\'http',
                        {"192.168.2.100",8080},
                        "/010/xmppcontrol",[],post,
                        {http_request_h,undefined,"keep-alive",undefined,
                         undefined,undefined,undefined,undefined,undefined,
                         undefined,...},
                        {"application/x-www-form-urlencoded","userId=12345"},
                        {http_options,"HTTP/1.1",infinity,true,
                         {essl,[]},
                         undefined,false,infinity,...},
                        "'http://192.168.2.100:8080/010/xmppcontrol",[],none,
                        [],1510504662776,undefined,undefined,false}},
                      infinity]}}
     in function  gen_server:call/3 (gen_server.erl, line 214)
     in call from httpc:handle_request/9 (httpc.erl, line 554)

你能说出httpc:request调用中的错误,因为当我从JS调用URL时,它运行正常。

这是我的JavaScript代码:

var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
asyncRequest = new XMLHttpRequest();
asyncRequest.addEventListener("readystatechange", stateChange, false);
asyncRequest.open('POST', 'http://192.168.2.100:8080/010/xmppcontrol?userId=' + userId , true);
asyncRequest.send(null);

提前致谢。

1 个答案:

答案 0 :(得分:2)

错误消息表明没有运行的进程绑定到名称httpc_manager。如httpcinets中所述,您需要运行inets应用程序才能使httpc请求正常工作。您可以通过在使用钢筋(在src/....app.src中)或手动启动inets应用程序时将应用程序添加到应用程序列表来执行此操作,例如

inets:start(),
httpc:request(...).