Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.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++ mongoose网络库:如何获得经过身份验证的用户?_C++_C_Mongoose Web Server - Fatal编程技术网

C++ mongoose网络库:如何获得经过身份验证的用户?

C++ mongoose网络库:如何获得经过身份验证的用户?,c++,c,mongoose-web-server,C++,C,Mongoose Web Server,我正在使用Cesanta mongoose网络库部署嵌入式服务器。 我使用摘要启用了http\u auth 我如何知道哪个用户登录了?您的问题有些模糊,因此我假设您主要关心在整个会话中跟踪唯一的用户,无论是通过IP地址、身份验证凭据还是通过其他方式 查看mg_http_server.h的API参考 具体地说,我认为函数“mg_http_parse_header2”就是您想要的。您应该能够使用此函数为所需字段解析收到的HTTP响应头 为“mg_http_parse_header2”提供的代码示例

我正在使用Cesanta mongoose网络库部署嵌入式服务器。 我使用摘要启用了http\u auth


我如何知道哪个用户登录了?

您的问题有些模糊,因此我假设您主要关心在整个会话中跟踪唯一的用户,无论是通过IP地址、身份验证凭据还是通过其他方式

查看mg_http_server.h的API参考

具体地说,我认为函数“mg_http_parse_header2”就是您想要的。您应该能够使用此函数为所需字段解析收到的HTTP响应头

为“mg_http_parse_header2”提供的代码示例几乎完全符合您的要求:

char user_buf[20];
char user = user_buf;
struct mg_str hdr = mg_get_http_header(hm, "Authorization");
mg_http_parse_header2(hdr, "username", &user, sizeof(user_buf));
// ... do something useful with user
if (user != user_buf) {
  free(user);
}
他们的示例显示了如何从HTTP头中的授权字段提取用户信息。如果您想根据自己的应用程序定制示例,Wikipedia有一个标准请求字段列表:

例如,“转发”字段提供识别客户端的原始IP地址的信息。“Authorization”字段包含易于恢复格式的用户名和密码,因此请记住,HTTPS提供了额外的安全层,而普通HTTP则存在潜在的漏洞