Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Boost Beast,如何提供登录凭据_C++_Http_Boost Beast - Fatal编程技术网

C++ Boost Beast,如何提供登录凭据

C++ Boost Beast,如何提供登录凭据,c++,http,boost-beast,C++,Http,Boost Beast,我正在尝试向网络上需要凭据的设备发送http请求。 例如,在webbrowser中,有效的请求是: 但是,我不知道如何使用BoostBeast将登录名和密码信息放入 我创建这样的请求: // 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 use

我正在尝试向网络上需要凭据的设备发送http请求。 例如,在webbrowser中,有效的请求是:

但是,我不知道如何使用BoostBeast将登录名和密码信息放入

我创建这样的请求:

  // 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");
//主机=mylogin:myPassword@10.11.2.118无法解决
//host=10.11.2.118已解析,但由于没有用户名和密码,我从设备中收到一个身份验证错误
自动结果=解析程序。解析(主机、端口)
...
//进行连接
...
请求请求请求{http::verb::get,path,11};
请求集(http::field::host,host);
请求集(http::field::user\u agent,BOOST\u BEAST\u VERSION\u STRING);
请求集(http::field::content_type,“application/json”);
请求集(http::field::accept,“vdn.dac.v1”);
请求中是否有我可以使用的字段

更新: 我发现以下库支持使用Boost Beast进行基本和摘要身份验证:。使用该库,我可以执行对上述URL的请求。这比我想象的要复杂得多

更新: 我切换到使用libcurl,它为您处理身份验证(我可以直接输入我提供的url并允许摘要身份验证)。

http::request req;//默认为HTTP/1.1
方法(http::verb::get);
请求目标(“mylogin:myPassword@10.11.2.118/axis cgi/virtualinput/activate.cgi?schemaversion=1和port=1“;
...

正确设置目标,但浏览器似乎使用这些参数进行摘要身份验证,因此以这种方式更改目标仍然会导致未经授权的访问。您必须阅读描述HTTP摘要身份验证()的RFC,并确保遵守协议。Beast并不是为你做这件事的,而是由你来阅读和编写适当的HTTP消息。我希望Beast为我做了这件事,但你是对的,所以我改用libcurl,它为你处理if。感谢@VinnieFalco和你的Boost Beast,以及RAvenGEr的简单Beast客户端,我能够得到它。启用digest auth的澄清确实很重要。推荐您,特别是RAvenGEr(lib的作者),对我帮助很大。谢谢大家和@VinnieFalco的野兽解放。请注意,简单Beast客户端需要为lib编译定义ENABLE_DIGEST,以允许如上所述的身份验证。
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");
...