在C中使用FastCGI的HMTL5/UTF8(fcgi_stdio.h) [英] HMTL5 / UTF8 using FastCGI in C (fcgi_stdio.h)

查看:114
本文介绍了在C中使用FastCGI的HMTL5/UTF8(fcgi_stdio.h)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个例子对我来说很好:

This example works fine for me:

#include "fcgi_stdio.h"

int main(void) {

while(FCGI_Accept() >= 0) {

    //Standard FastCGI Example Web-page
    printf("Content-type: text/html\r\n"
        "\r\n"
        "<title>FactCGI Example</title>"
        "<h1>Example Website</h1>"
        "Some text...\r\n");

    FCGI_Finish();
}

return 0;
}

但是因为我的网页上需要UTF8字符,所以我认为我应该使用html5格式化网页.这是我的骨架,可以将其作为独立文件呈现:

But since I need UTF8 chars on my web-page, I thought I'd format the web page using html5. This was my skeleton which renders ok as a stand-alone file:

<!DOCTYPE html>
<html>

<head>
<title>FactCGI Example</title>
</head>

<body>
<h1>Example Website</h1>
<p>Some text...</p>
</body>

</html>

但是按如下所示将其折叠到fcgi脚本中时,在脚本加载时出现内部服务器错误".

But when folded this into the fcgi script as follows, I get an 'Internal Server Error' on script load.

#include "fcgi_stdio.h"

int main(void) {

while(FCGI_Accept() >= 0) {

    //Using html5 for the web-page
    printf("<!DOCTYPE html>\r\n"
        "<html>\r\n"
        "\r\n"
        "<head>\r\n"
        "<title>FactCGI Example</title>\r\n"
        "</head>\r\n"
        "\r\n"
        "<body>\r\n"
        "<h1>Example Website</h1>\r\n"
        "<p>Some text...</p>\r\n"
        "</body>\r\n"
        "\r\n"
        "</html>\r\n");

    FCGI_Finish();
    }

return 0;
}

Fedora 23,httpd 2.8.18,Firefox 43.0.3,gcc 5.3.1-2

Fedora 23, httpd 2.8.18, Firefox 43.0.3, gcc 5.3.1-2

Google搜索表示所有fcgi,网页均以内容类型:text/html"开头.

Googling indicates all fcgi, web pages start with "Content-type: text/html".

我犯了一些愚蠢的错误,还是fcgi只是不支持html5?

Have I made some silly mistake or does fcgi just not support html5?

还有其他方法可以使用fcgi启用UTF8支持吗?

Is there some other way to enable UTF8 support using fcgi?

推荐答案

该错误很可能是由于输出中没有Content-type HTTP标头而引起的.另外,如果要使用UTF-8,则应在Content-type标头中将UTF-8指定为字符集.但是,您无需使用HTML5即可在网页中使用UTF-8.该编码也可以与较早的HTML版本一起使用.

The error is likely caused because you don't have the Content-type HTTP header in your output. Also, if you want to use UTF-8, then you should specify UTF-8 as the charset in the Content-type header. But you don't need to use HTML5 to use UTF-8 in your web page; the encoding can be used with older HTML versions as well.

这是添加了Content-type标头和UTF-8参数的代码.

Here's your code with the Content-type header and UTF-8 parameter added.

#include "fcgi_stdio.h"

int main(void) {

while(FCGI_Accept() >= 0) {

    //Using html5 for the web-page
    printf("Content-type: text/html charset=utf-8\r\n"
        "\r\n"
        "<!DOCTYPE html>\r\n"
        "<html>\r\n"
        "\r\n"
        "<head>\r\n"
        "<title>FactCGI Example</title>\r\n"
        "</head>\r\n"
        "\r\n"
        "<body>\r\n"
        "<h1>Example Website</h1>\r\n"
        "<p>Some text...</p>\r\n"
        "</body>\r\n"
        "\r\n"
        "</html>\r\n");

    FCGI_Finish();
    }

return 0;
}

这篇关于在C中使用FastCGI的HMTL5/UTF8(fcgi_stdio.h)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆