erlang常用组件使用
时间:2010-10-13 来源:sw2wolf
。httpc
-module(httpc_post_stream_test).
-compile(export_all).
-define(LEN, 1024 * 1024).
prepare_data() ->
crypto:start(),
{ok, Fd} = file:open("test_data.dat", [binary, write]),
ok = file:write(Fd, lists:duplicate(crypto:rand_uniform(8182, 32768), "1")),
ok = file:close(Fd).
test() ->
inets:start(),
ok = prepare_data(),
{ok, Fd1} = file:open("test_data.dat", [binary, read]),
BodyFun = fun(Fd) ->
case file:read(Fd, 512) of
eof -> eof;
{ok, Data} -> {ok, Data, Fd}
end
end,
{ok, {{_,200,_}, _, _}} = httpc:request(post, {"http://localhost:8888",[], "text/plain", {chunkify, BodyFun, Fd1}}, [], []),
ok = file:close(Fd1).