Loose-Info.com
Last Update 2019/04/28
TOP - 各種テスト - Web関連 - Webサーバ動作確認

テスト概要

C言語によるソースファイルをコンパイルして作成したCGIの実行テスト

実行環境

GCC-8.2.0
GNU C Library 2.28
Apache 2.4.34


test.html(ドキュメントルート配下に配置)
<html> <head> <title>test</title> <meta charset="UTF-8"> </head> <body> <form action="/cgi-bin/test.cgi" method="GET"> <input type="button" name="test1" value="送信" onclick="submit()"> </form> </body> </html>

test.cgi(下記ソースコードのコンパイル後のバイナリを、cgi-binディレクトリに配置)
#include <stdio.h> #include <time.h> int main(void) { time_t tTime; time(&tTime); printf("Content-type: text/html\n\n"); printf("<html>\n"); printf("<head>\n"); printf("<meta charset=\"UTF-8\">\n"); printf("<title>TEST</title>\n"); printf("</head>\n"); printf("<body>\n"); printf("<p>接続成功。時刻は、%s です。</p>\n", ctime(&tTime)); printf("</body>\n"); printf("</html>\n"); return 0; }

実行結果
接続成功。時刻は、Wed Apr 10 06:20:36 2019 です。