2

I want to send a POST request and data to be displayed on the page (as in the example below)

What changes should be made to support special characters and 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>");
    }
}

Thank's

Valy Dvweb
  • 35
  • 8

0 Answers0