サーバーは実際にリクエストを受け取りますか? また、ホスト名 (エイリアス) を適切に処理していますか?
.hosts ファイルに追加した後
ウェブサーバーのログをチェックして、リクエストがどのように受信されたかを確認してください...
curl には、送信されたリクエストと受信したレスポンスをダンプするオプションがあります。これは trace と呼ばれ、ファイルに保存されます。
- 痕跡
ホストまたはヘッダー情報が欠落している場合は、構成オプションを使用してそれらのヘッダーを強制できます。
コマンドラインでcurlリクエストが機能するようにしてから、PHPで実装しようとします。
設定オプションは
-K/--config
curl に関連するオプションはこちら
--trace 指定された出力ファイルへの、説明情報を含むすべての着信および発信データの完全なトレース ダンプを有効にします。出力を stdout に送信するには、ファイル名として「-」を使用します。
This option overrides previous uses of -v/--verbose or --trace-ascii.
If this option is used several times, the last one will be used.
-K/--config curl 引数を読み取る構成ファイルを指定します。構成ファイルは、実際のコマンド ラインに記述されているかのように使用されるコマンド ライン引数を書き込むことができるテキスト ファイルです。オプションとそのパラメータは、空白、コロン、等号、またはそれらの任意の組み合わせで区切って、同じ構成ファイル行で指定する必要があります (ただし、推奨される区切り文字は等号です)。パラメータに空白を含める場合は、パラメータを引用符で囲む必要があります。二重引用符内では、次のエスケープ シーケンスを使用できます: \、\"、\t、\n、\r、および \v。他の文字の前にあるバックスラッシュは無視されます。構成行の最初の列が「#」の場合文字、行の残りの部分はコメントとして扱われます。
Specify the filename to -K/--config as '-' to make curl read the file from stdin.
Note that to be able to specify a URL in the config file, you need to specify it using the --url option, and not by simply writing the URL on its own line. So, it could look similar to this:
url = "http://curl.haxx.se/docs/"
Long option names can optionally be given in the config file without the initial double dashes.
When curl is invoked, it always (unless -q is used) checks for a default config file and uses it if found. The default config file is checked for in the following places in this order:
1) curl tries to find the "home dir": It first checks for the CURL_HOME and then the HOME environment variables. Failing that, it uses getpwuid() on UNIX-like systems (which returns the home dir
given the current user in your system). On Windows, it then checks for the APPDATA variable, or as a last resort the '%USERPROFILE%\Application Data'.
2) On windows, if there is no _curlrc file in the home dir, it checks for one in the same dir the curl executable is placed. On UNIX-like systems, it will simply try to load .curlrc from the deter-
mined home dir.
# --- Example file ---
# this is a comment
url = "curl.haxx.se"
output = "curlhere.html"
user-agent = "superagent/1.0"
# and fetch another URL too
url = "curl.haxx.se/docs/manpage.html"
-O
referer = "http://nowhereatall.com/"
# --- End of example file ---
This option can be used multiple times to load multiple config files.