我使用gnu microhttpd库在软件上工作,并且工作正常。无论如何使我的html输出对人类友好,我想使用CSS等。听起来像是一个错误,但我没有看到:
所以,如果有人可以帮助。
string sPage;
sPage = "<html><head><link rel = \"stylesheet\" type = \"text/css\" href = \"./template.css\" /></head><body style=\"background-color:red><a href=\"../test1.htm\">Link to this folder</a><div class=\"flex-container\"><div>Le processus " + Process
+ " n\'est pas actif, impossible de se connecter</div></div><IMG src=\"../images/TrafficLights.png\"></body></html>";
struct MHD_Response *response;
int ret;
//response = MHD_create_response_from_buffer (strlen (page),(void*) page, MHD_RESPMEM_PERSISTENT);
response = MHD_create_response_from_buffer (strlen (sPage.c_str()),(void*) sPage.c_str(), MHD_RESPMEM_PERSISTENT);
ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
MHD_destroy_response (response);
return ret;
摘自MHD_queue_response的文档:
[mode]缓冲区的内存管理选项;如果缓冲区是静态/全局内存,则使用MHD_RESPMEM_PERSISTENT;如果缓冲区是堆分配的,则使用MHD_RESPMEM_MUST_FREE;如果缓冲区在临时内存中(即在堆栈上),则应使用MHD_RESPMEM_MUST_COPY释放;如果缓冲区在临时内存中(即在堆栈上),则必须由MHD复制;
所以要么将sPage
的全部内容静态地定义,要么让堆栈分配sPage
,但将模式设置为MHD_RESPMEM_MUST_COPY
。