2016-01-09 1 views
0

Cet exemple fonctionne très bien pour moi:HMTL5/UTF8 en utilisant FastCGI en C (fcgi_stdio.h)

#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; 
} 

Mais depuis que je besoin UTF8 sur mon web caractères page, je pensais que je formater la page web en utilisant html5. Ce fut mon squelette qui rend ok comme un fichier autonome:

<!DOCTYPE html> 
<html> 

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

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

</html> 

Mais une fois plié ceci dans le script fcgi comme suit, je reçois un « Internal Server Error » sur la charge de script.

#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

recherche sur Google indique toutes les fcgi, les pages Web commencent par "Content-Type: text/html".

Ai-je commis une erreur stupide ou est-ce que fcgi ne supporte pas html5?

Existe-t-il un autre moyen d'activer le support UTF8 à l'aide de fcgi?

+0

L'en-tête Content-type de votre version HTML5 ne vous manque pas? –

Répondre

0

L'erreur est probablement due au fait que vous n'avez pas l'en-tête HTTP Content-type dans votre sortie. En outre, si vous souhaitez utiliser UTF-8, vous devez spécifier UTF-8 comme charset dans l'en-tête Content-type. Mais vous n'avez pas besoin d'utiliser HTML5 pour utiliser UTF-8 dans votre page Web; L'encodage peut également être utilisé avec des versions HTML plus anciennes.

Voici votre code avec l'en-tête Content-type et le paramètre UTF-8 ajouté.

#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; 
}