を失敗し、私はここに、この機能があります。投稿JSONデータと
public static function call($action, array $args)
{
$post_args = array(
'action' => $action,
'args' => $args
);
$stream = json_encode($post_args);
$headers = array(
'Content-type: application/json',
'Accept: application/json',
'Expect:'
);
$userpwd = self::$_user.':'.sha1(sha1(self::$_pass));
$ch = curl_init();
$args = array(
CURLOPT_URL => self::$_url,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $stream,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_USERPWD => $userpwd
);
curl_setopt_array($ch, $args);
$res = curl_exec($ch);
$data = json_decode($res, true);
if (isset($data) === TRUE
&& empty($data) === FALSE
) {
$res = $data;
}
return $res;
}//end call()
と私が投稿してるURLで、私はやってる:
echo file_get_contents('php://input');
をしかなっていないが、データを投稿しても何が問題なの?私は行き詰まっている。
また、リダイレクトを行わずにローカルマシンの単純な仮想ホストURLに投稿するときに、CURLOPT_FOLLOWLOCATIONをTRUEに設定する必要があります。
EDIT:
public static function call($action, array $args)
{
$post_args = array(
'action' => $action,
'args' => $args
);
$stream = json_encode($post_args);
$userpwd = self::$_user.':'.sha1(sha1(self::$_pass));
$opts = array(
'http' => array(
'method' => 'POST',
'header' => array(
"Authorization: Basic ".base64_encode($userpwd),
"Content-type: application/json"
),
'content' => $stream
)
);
$context = stream_context_create($opts);
$res = '';
$fp = fopen(self::$_url, 'r', false, $context);
if($fp){
while (!feof($fp)){
$res .= fread($fp, 128);
}
}
return $res;
}//end call()
なしの成功を:
がそうのようにfopenでそれをやり直してみました。 resultと一緒にステータスを渡すので、接続はcurlとfopenで動作します(これは単なるphp://入力ストリームです)。何か案は?
あなたのPHPを置くフォルダに.htaccessファイルを置きます。 htaccessでこれらを書き留めてください: RewriteEngine On RewriteRule。* myfile.php [PT、L] すべてのリクエストはmyfile.phpに行きます。 – tcak
動作していないようです。私はMoved Permanently 301レスポンスを取得し、CURLOPT_FOLLOWLOCATIONをtrueに設定すると、前と同じように空の結果が得られます。 – donkapone
http://www.noupe.com/php/10-mod_rewrite-rules-you-should-know.htmlこれを確認してください。 htaccessを正しく書くのに役立つかもしれません。多分あなたは間違って書いたでしょう。また、何か、多分日付の時間、またはあなたが送ったリクエストをphpファイルのファイルに書き込もうとします。あなたはそれが正しく動作することを理解することができます。 – tcak