在ejabberd模块中我使用这种方法:
httpc:request(post,{Url,Header
似乎没有异步,有没有办法用erlang在一个单独的线程上启动它???
答案 0 :(得分:0)
Sample method-
// module name - sample
http_request(Method,Url,Body)->
httpc:request(Method, {Url, [], "application/x-www-form-urlencoded", Body}, [], []).
你会这样打电话 -
spawn(sample, http_request, [post,”www.sample.com”,”some sample data”]).
%% syntax spawn(Module, Name, Args) -> pid()
http://erlang.org/doc/getting_started/conc_prog.html http://erlang.org/doc/reference_manual/processes.html
答案 1 :(得分:0)
我用过这个:
spawn(mod_http_offline, http_request, [Url, Post]).
% Function that make a call
http_request(Url, Post)->
TypeData = "application/x-www-form-urlencoded",
Header = [],
HTTPOptions = [],
Options = [],
httpc:request(post, {Url, Header, TypeData,list_to_binary(Post)}, HTTPOptions, Options).
但是当我编译时,获得这个:
Warning: function http_request/2 is unused
并且不调用函数