gpt4 book ai didi

http - 如何 http :post file with httpc:request in erlang?

转载 作者:可可西里 更新时间:2023-11-01 17:00:31 26 4
gpt4 key购买 nike

我以前是这样写的:

inets:start(),
ssl:start(),
ParaUrl = io_lib:format("http://xxx/passport?accessn=~s",[Access]),
ParaStr = io_lib:format("id=~p",[Id]),
RegUsr = httpc:request(post,{ParaUrl, [],"application/x-www-form-urlencoded", list_to_binary(ParaStr)},[],[])

但它只是用于字符串而不是二进制文件,谁能告诉我如何使用 httpc:request 发布二进制文件?

最佳答案

对我有用:

 {ok, F} = file:read_file("warning.gif"),
httpc:request(post,{Url, [],"multipart/form-data", F},[],[]).

我在 cowboy 网络服务器上收到了函数 cowboy_req:body(Req):

{ok,<<71,73,70,56,57,97,11,0,11,0,230,64,0............>>,
{http_req,#Port<0.65562>,ranch_tcp,keepalive,<0.8736.0>,<<"POST">>,
'HTTP/1.1',
{{127,0,0,1},58154},
<<"localhost">>,undefined,8000,<<"/test1">>,
[<<"test1">>],
<<>>,undefined,[],
[{<<"content-type">>,<<"multipart/form-data">>},
{<<"content-length">>,<<"516">>},
{<<"te">>,<<>>},
{<<"host">>,<<"localhost:8000">>},
{<<"connection">>,<<"keep-alive">>}],
[{<<"content-length">>,516},
{<<"expect">>,undefined},
{<<"content-length">>,516},
{<<"connection">>,[<<"keep-alive">>]}],undefined,[],done,undefined,<<>>,true,waiting,[],<<>>,
undefined}}

关于http - 如何 http :post file with httpc:request in erlang?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39222517/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com