我试图将http请求发送到我们网络上需要凭据的设备。
例如,在Web浏览器中,有效的请求为:

http://mylogin:[email protected]/axis-cgi/virtualinput/activate.cgi?schemaversion=1&port=1

但是,我不知道如何在使用Boost野兽时输入登录名和密码信息。

我这样创建请求:

  // host = mylogin:[email protected] 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并允许摘要身份验证)。

最佳答案

http::request<http::string_body> req; // defaults to HTTP/1.1
req.method(http::verb::get);
req.target("mylogin:[email protected]/axis-cgi/virtualinput/activate.cgi?schemaversion=1&port=1");
...

10-06 11:07