2

我正在尝试向我们网络上需要凭据的设备发送 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 身份验证)。

4

2 回答 2

1
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");
...
于 2019-09-18T01:58:31.760 回答
0

您需要将字符串 mylogin:myPassword 编码为 base64 格式,然后在其前面加上“Basic”,如下所示:

req.set(http::field::authorization, "Basic bXlsb2dpbjpteVBhc3N3b3Jk");
...
于 2021-07-09T01:42:13.200 回答