我正在尝试创建一个服务器,该服务器将以非英语语言提供页面,我正在使用以下代码测试libmicrohttpd:

static int
answer_to_connection(void* cls, struct MHD_Connection* connection,
                     const char* url, const char* method,
                     const char* version, const char* upload_data,
                     size_t* upload_data_size, void** con_cls)
{
    char *page = "<html><head><meta charset='UTF-8'></head><body>हैलो यूनिकोड</body></html>";


    struct MHD_Response* response;
    int ret;

    response =
        MHD_create_response_from_buffer(strlen(page), (void *)page,
                                        MHD_RESPMEM_PERSISTENT);

    ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
    MHD_destroy_response(response);

    return ret;
}

但这不是工作和付出????? 浏览器上的字符。
有谁能告诉我libmicrohttpd是否支持Unicode,如果支持,那么如何支持?

最佳答案

正如我在评论中所写的,您必须确保字符串的格式为UTF-8。标准char类型根据所选代码页或本地设置字符串格式,如果解释为UTF-8,则会产生格式错误的字符。
如果您使用的是带有u8作为的C11编译器前缀字符串:

char *page = u8"<html><head><meta charset='UTF-8'></head><body>हैलो यूनिकोड</body></html>";

如果编译器不支持UTF-8,则需要一个外部工具,使用十六进制转义或八进制等来格式化字符串。

07-28 12:43