如何在julia中使用LibCURL添加标题

问题描述 投票:1回答:1

我想进行api调用,并将curl内容类型标头设置为application / json,

julia libcurl
1个回答
0
投票

这里是使用测试服务postman-echo.com的样本

Bash命令(在基于Unix的系统中使用单撇号:

$ curl --location --header "hfoo:hbar" --request GET "https://postman-echo.com/get?foo1=bar1"

Julia等效项:

julia> using HTTP; d = HTTP.request(:GET, "https://postman-echo.com/get?foo1=bar1",["hfoo"=>"hbar"]);

julia> println(String(d.body))
{"args":{"foo1":"bar1"},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-5ec438fa-c2bf3d5d8a300e08685f833d","content-length":"0","hfoo":"hbar","user-agent":"HTTP.jl/1.4.1"},"url":"https://postman-echo.com/get?foo1=bar1"}
© www.soinside.com 2019 - 2024. All rights reserved.