FastCGI Post(UTF8)

时间:2016-05-06 23:58:49

标签: c utf-8 stdin fastcgi mod-fastcgi

我想发送一个POST请求和要在页面上显示的数据 (如下例所示)

应该对支持特殊字符和UTF-8进行哪些更改?

char *get_post_body() {

    char *content_length = getenv("CONTENT_LENGTH");
    if(!content_length) {
        return "";
    }

    int size = atoi(content_length);
    char *body = (char *) calloc(size + 1, sizeof(char));
    fread(body, size, 1, stdin);

    return body;
}


int main(void)
{
    while(FCGI_Accept() >= 0) {

        printf("Content-type: text/html charset=utf-8\r\n\r\n<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n<title>Hello, World!</title>\n</head>\n<body>\n<h1>Hello, World!</h1>\n");

        printf( get_post_body() );
        printf("<form method=\"post\"><input type=\"text\" name=\"set\" /><button type=\"submit\">SEND</button></form></body>\n</html>");
    }
}

感谢&#39; S

0 个答案:

没有答案
相关问题