ejabberd HTTP request handlers处理 post get

小例子http://www.process-one.net/en/wiki/ejabberd_HTTP_request_handlers/



处理GET

http://langxianzhe.com?version=1&token=c617b5435134c1735255edeb4f4b93b4&test=Test

关键是怎么处理Rquest#request.q中数据 以[{},{}]形式组成

我暂时采用了下面的方法 []中元素顺序 需 和url 中的顺序一致
Erlang代码  收藏代码

    process([], #request{method = 'GET', q=[{"version", Version}, {"token", Token}, {"test", test} ], host = Server,  ip = {IP, _Port}, data = Data}= Request) -> 

处理POST
http://langxianzhe.com/
<operator>
    <version>1</version>
    <test>test</test>
    <token>token</token>
</operator>
关键是对Data的解析
Erlang代码  收藏代码

    process([], #request{method = 'POST',host = Server,  ip = {IP, _Port}, data = Data}= _Request) -> 
     27     ?DEBUG("in ~p :ip = ~p,data = ~p~n", [?MODULE,IP, Data]), 
     28     IpStr = inet_parse:ntoa(IP), 
     29     Tag = xml_stream:parse_element(Data), 
     30     try 
     31         case Tag of 
     32             {xmlelement, "operator", [{_Type, "bind"}], SubEl} -> 
     33                 Version = xml:get_subtag_cdata(Tag, "version"), 
     34                 Vendor = xml:get_subtag_cdata(Tag, "test"), 
     35                 Token = xml:get_subtag_cdata(Tag, "token"),

你可能感兴趣的:(handler)