【问题标题】:httprc:request throws exception exit: {noproc, {gen_server,call, [httpc_manager ...]}}httprc:request 抛出异常退出:{noproc, {gen_server,call, [httpc_manager ...]}}
【发布时间】:2018-04-25 08:47:28
【问题描述】:

我想在我的 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);

提前致谢。

【问题讨论】:

    标签: erlang httpc


    【解决方案1】:

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

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

    【讨论】:

    • 我没有收到任何错误,但是我的 servlet 没有被执行,或者是 httpc 调用以错误的格式到达 servlet?
    • URL 的开头还有一个额外的单引号。您可以尝试删除它吗?
    • 哦,对不起,没看到。现在它工作正常。谢谢你:)
    猜你喜欢
    • 2015-11-05
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 2013-09-05
    • 2011-05-30
    • 1970-01-01
    相关资源
    最近更新 更多