0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CGIでステータスコードを任意の値に設定

Last updated at Posted at 2025-12-06

QUERY_STRINGに ?code=<値> を設定することで、<値> をHTTPステータスコードとして応答するサンプル。異常系の考慮はまったくないテスト用。

スクリプト部分のみ。
IISやApache HTTP Server のCGI設定方法は省略。

BATファイル
@echo off
rem CGI(BAT) SAMPLE. %QUERY_STRING%= code=<statuscode>

rem get code from environment.
for /f "tokens=2 delims==" %%a in ("%QUERY_STRING%") do (
  set "code=%%a"
)

rem make response.
echo status: %code%
echo Content-type: text/plain
echo.
echo STATUSCODE = %code%
BASH
#!/bin/bash
# CGI(bash) SAMPLE. $QUERY_STRING= code=<statuscode>

# get code from environment.
code=$(echo $QUERY_STRING | cut -d= -f2)

# make response.
echo status: $code
echo Content-type: text/plain
echo
echo STATUSCODE = $code
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?