PHPを使用してJSON APIを使用しようとしています。PHPを使用したJSON APIの使用
私は応答を取得するためにCURLを使って試してみました:
curl 'http://104.239.130.176:3000/api/users/authenticate?email=my_username_here&password=my_password'
これは私の端末のいずれかの応答を与えるものではありません。私も、ユーザー名のための電子メールを交換しようとしている
:
curl 'http://104.239.130.176:3000/api/users/authenticate?username=my_username_here&password=my_password'
私は、PHPファイルに次のように書かれているが、これは私のブラウザで404エラーが発生します。
<?php
// Parameters
$tpm_base_url = 'http://104.239.176.130:3000/'; // ending with/
$req_uri = 'api/users/authenticate'; // GET /passwords.json
$username = 'my_username';
$password = 'my_password';
// Request headers
$headers = array(
'Content-Type: application/json; charset=utf-8'
);
// Request
$ch = curl_init($tpm_base_url . $req_uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE); // Includes the header in the output
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); // HTTP Basic Authentication
$result = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// Get headers and body
list($headers, $body) = explode("\r\n\r\n", $result, 2);
$arr_headers = explode("\r\n", $headers);
$arr_body = json_decode($body, TRUE);
// Show status and array of passwords
echo 'Status: ' . $status . '<br/>';
print_r($arr_body);
私はここで間違っていますか分かりません。 API開発者の指示は次のとおりです。
APIには基本的なJWTセキュリティがあり、最初の要求トークンがあります。
POSTリクエストへ: http://104.239.176.130:3000/api/users/authenticate
あなたはfile_geを試しましたか? curlではなくt_contents(url)? –
** POST **に....私が言うことができる限り、あなたはただGETリクエストをしています。そして、あなた自身をロールしようとするのではなく、適切なHTTPライブラリを使うべきです。あなたに多くの時間を節約します。 –