2016-12-28 33 views
0

我想创建非英语语言这将服务器网页服务器的工作,我使用此代码测试libmicrohttpd:的Unicode HTML缓冲区不是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,如果是的话如何?

+0

我做到了,但没有运气。 –

+0

看看这里:http://stackoverflow.com/questions/1696619/displaying-unicode-symbols-in-html。确保你的字符串是用UTF-8格式化的。如果您使用的是C11编译器前缀字符串'u8'为:'字符*页= U8" हैलोयूनिकोड“;' –

+0

啊那的工作! !谢谢你,加上这个答案,我会标记为正确的 –

回答

2

正如我已经在评论中写道,你必须确保你的字符串格式为UTF-8。标准char根据选定的代码页或本地字符串格式化字符串,如果解释为UTF-8,则会给出错误的形成字符。

如果您使用的是C11编译器前缀字符串u8为:

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

如果你的编译器不支持UTF-8,你需要在使用十六进制转义或八进制或格式化字符串外部工具类似。