我正在尝试向网络上需要凭据的设备发送http请求。例如,在For浏览器中,可以工作的请求是:
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并允许摘要式身份验证)。
发布于 2019-09-18 09:58:32
http::request<http::string_body> req; // defaults to HTTP/1.1
req.method(http::verb::get);
req.target("mylogin:myPassword@10.11.2.118/axis-cgi/virtualinput/activate.cgi?schemaversion=1&port=1");
...发布于 2021-07-09 09:42:13
您需要将字符串mylogin:myPassword编码为base64格式,然后在前面加上"Basic“,如下所示:
req.set(http::field::authorization, "Basic bXlsb2dpbjpteVBhc3N3b3Jk");
...https://stackoverflow.com/questions/57977916
复制相似问题