gpt4 book ai didi

post - 在 Erlang 中的 HTTPC 发布请求中设置 header

转载 作者:行者123 更新时间:2023-12-01 06:18:23 28 4
gpt4 key购买 nike

我正在尝试从 Erlang 发出 HTTPC post 请求:

httpc:request(post, {"https://android.googleapis.com/gcm/send",[{"Authorization","key=api_key_generated_at_googleaccount"}],[{"Content-Type","application/json"}],Body},[],[])

但是每次我发起这个请求时,我的 Erlang shell 都会挂起。请求中是否有问题?

最佳答案

我认为您在 http:request/4 的手册中混淆了 httpc 的参数:

request(Method, Request, HTTPOptions, Options)

Request = request()
request() = {url(), headers()} |
{url(), headers(), content_type(), body()}
content_type() = string()
上面你可以看到 content_type() 应该是 string() 而不是 [{string(),string()}]
如果将整个 request() 放入变量中,则更容易阅读:
10> inets:start().
ok
11> ssl:start().
ok
12> Body = "some cool json",
12> Request = {"https://android.googleapis.com/gcm/send", [{"Authorization","key=blabla"}], "application/json", Body},
12> httpc:request(post, Request, [], []).
{ok,{{"HTTP/1.1",401,"Unauthorized"},
[{"cache-control","private, max-age=0"},
{"date","Tue, 03 Feb 2015 07:19:07 GMT"},
{"accept-ranges","none"},
{"server","GSE"},
{"vary","Accept-Encoding"},
{"content-length","147"},
{"content-type","text/html; charset=UTF-8"},
{"expires","Tue, 03 Feb 2015 07:19:07 GMT"},
{"x-content-type-options","nosniff"},
{"x-frame-options","SAMEORIGIN"},
{"x-xss-protection","1; mode=block"},
{"alternate-protocol","443:quic,p=0.02"}],
"<HTML>\n<HEAD>\n<TITLE>Unauthorized</TITLE>\n</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\" TEXT=\"#000000\">\n<H1>Unauthorized</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n"}}

关于post - 在 Erlang 中的 HTTPC 发布请求中设置 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28292576/

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