HTMLリクエストをデバッグする
| 日付 | 2001/07/27 |
|---|---|
| ID | 01-662 |
| バージョン | v6.5.x and 6.7.x |
| プラットフォーム | Windows and Mac |
4th DimensionにおいてWebサーバのコードをデバッグする時、Webブラウザがどのようなリクエストを送ってきているのかを正確に確かめること 有用です。以前のTipでは、ネットワークキャプチャーユーティリティを使う方法について説明しました。
http://www.4d.com/support/tips00-287.html
しかし、もっと簡単にリクエスト内容を取得する方法があります。まずデータベースメソッドのOn Web Connection上に次のコードを設置します。
` Database Method: On Web Connection
` Capture the raw HTTP header into a user-specified file
` so we don't break compiled
C_TEXT($1;$2;$3;$4;$5;$6;$HTTPHeader)
` 4D places HTTP Header into second parameter to OWC
$HTTPHeader:=$2
` display standard put file dialog
$docRef:=Create document("")
If (OK=1)` user didn't cancel dialog
` out goes the raw header
SEND PACKET($docRef;$HTTPHeader)
CLOSE DOCUMENT($docRef)` be a good citizen
ALERT("The header was saved.")
Else
ALERT("The header was not saved.")
End if
TRACE
` NOTE: the ALERT command can be used
` in both Contextual and Non-contextual mode
` for a short text-only response.
そして次のように記述した「index.html」を配置します
<html> <head> <title>Capture HTTP Header Test</title> </head> <br/> <h1>Capture HTTP Header Test</h1> <br/> <a href="/4DCGI/RequestedURL">Click to test.</a> </html>
ブラウザに表示された「Click to test」リンクをクリックした後、Webサーバ側に作成されたテキストファイルには後述のようなデータが得られるはずです。もちろん内容は、使用したブラウザによって異なるなので、全く同じ記録にはなりません。
GET /4DCGI/RequestedURL HTTP/1.1 Host: 10.96.0.29 Accept: */* Accept-Language: en Connection: Keep-Alive User-Agent: Mozilla/4.0 (compatible; MSIE 4.5; Mac_PowerPC) UA-OS: MacOS UA-CPU: PPC Extension: Security/Remote-Passphrase