I want to invoke httprc:request
in my erlang program, but I get an exception, which has no information to me, what went wrong.
This is my code:
print_helloworld() ->
Body = "userId=12345",
httpc:request(post,
{
"'http://192.168.2.100:8080/010/xmppcontrol", [],
"application/x-www-form-urlencoded",
Body
}, [], []).
This is my exception:
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)
Can you tell what is wrong in the httpc:request
call, because when I call the URL from JS, it works fine.
This is my code from 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);
Thanks in advance.
The error message says that there's no process running that is bound to the name httpc_manager
. As documented in httpc
and inets
, you need to have the inets
application running to make httpc requests work. You can do this either by adding the application to the applications list when using rebar (in src/....app.src
) or starting the inets
application manually, e.g.
inets:start(),
httpc:request(...).