我正在尝试向我们网络上需要凭据的设备发送 http 请求。例如,在网络浏览器中,有效的请求将是:
http://mylogin:myPassword@10.11.2.118/axis-cgi/virtualinput/activate.cgi?schemaversion=1&port=1
但是,我不知道如何在使用 boost beast 时输入登录名和密码信息。
我这样创建请求:
// host = mylogin:myPassword@10.11.2.118 does not resolve
// host = 10.11.2.118 resolves but I get an authentication error from the device due to no username and password
auto results = resolver.resolve(host, port)
...
//Do the connecting
...
http::request<http::string_body> req{http::verb::get, path, 11};
req.set(http::field::host, host);
req.set(http::field::user_agent, BOOST_BEAST_VERSION_STRING);
req.set(http::field::content_type, "application/json");
req.set(http::field::accept, "vdn.dac.v1");
请求中是否有我可以使用的字段?
更新:我发现以下库支持使用 Boost Beast 进行基本和摘要式身份验证:https ://github.com/RAvenGEr/simple-beast-client 。使用该库,我可以执行对上述 URL 的请求。它比我想要的要复杂。
更新:我切换到使用为您处理身份验证的 libcurl(我可以将我提供的 url 直接放入并允许 Digest 身份验证)。