JSONコンテンツをリモートRESTエンドポイントにPOSTしようとしていますが、配信時に「content」値が空のように見えます。他のすべてのヘッダーなどは正しく受信されており、Webサービスはブラウザーベースのテストクライアントで正常にテストされています。
'content'フィールドを指定する以下の構文に問題がありますか?
$data = array("username" => "duser", "firstname" => "Demo", "surname" => "User", "email" => "example@example.com");
$data_string = json_encode($data);
$result = file_get_contents('http://test.com/api/user/create', null, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => array('Content-Type: application/json'."\r\n"
. 'Authorization: username:key'."\r\n"
. 'Content-Length: ' . strlen($data_string) . "\r\n"),
'content' => $data_string)
)
));
echo $result;