mod_restful
mod_restful copied to clipboard
mod_restful on ejabberd_16.01 - Problem with module mod_restful
hi i am working on ejabberd_16.01 and i'm facing problems using mod_restful.
ejabberd.yml:
listen:
-
port: 8088
ip: "::"
module: ejabberd_http
request_handlers:
"/api": mod_restful
modules:
mod_restful:
api:
-
path: ["admin"]
module: mod_restful_admin
params:
key: "secret" ## if you want to use basic auth, you need to remove this line
allowed_commands: [srg_create, srg_user_add, status, registered_users]
I added the module:
> sudo /opt/ejabberd-16.01/bin/ejabberdctl module_install mod_restful
src/mod_restful_admin.erl:63: Warning: behaviour en_restful_api undefined
src/mod_restful_register.erl:32: Warning: behaviour en_restful_api undefined
ok
when I call :
POST /api/admin HTTP/1.1
Host: 173.39.250.116:8088
Content-Type: application/json
Cache-Control: no-cache
{"key":"secret", "command":"status", "args":[]}
I get :
<?xml version='1.0'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
</head>
<body>
<h1>401 Unauthorized</h1>
</body>
</html>
any idea what am I missing?
Thanks Itay
one more pice of info, the ejabberd log :
2016-02-24 12:25:28.990 [info] <0.619.0>@ejabberd_listener:accept:333 (#Port<0.15943>) Accepted connection 10.149.215.173:59829 -> 192.168.0.26:8088
2016-02-24 12:25:28.991 [info] <0.623.0>@ejabberd_http:init:158 started: {gen_tcp,#Port<0.15943>}
2016-02-24 12:25:28.991 [error] <0.623.0> Processing throwed error {bad match,false}
trace: [{mod_restful,handle_request,3,[{file,"src/mod_restful.erl"},{line,179}]},{mod_restful,process,2,[{file,"src/mod_restful.erl"},{line,161}]},{ejabberd_http,process,5,[{file,"src/ejabberd_http.erl"},{line,363}]},{ejabberd_http,process_request,1,[{file,"src/ejabberd_http.erl"},{line,451}]},{ejabberd_http,process_header,2,[{file,"src/ejabberd_http.erl"},{line,291}]},{ejabberd_http,parse_headers,1,[{file,"src/ejabberd_http.erl"},{line,211}]},{ejabberd_http,init,2,[{file,"src/ejabberd_http.erl"},{line,164}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,237}]}]
any ideas?
You need to provide a valid hostname via the HTTP request. 173.39.250.116 is the hostname you provide in your request, but I'm guessing this is not a hostname you have configured your server to use.
That solved my problem.
Thanks!