phpunitを使用してLaravel APIをテストしようとしていて、$this->call();
メソッドを使用してコールを実行し、正常に動作しているかどうかを確認しています。PhpUnit経由のトークン付きlaravel 5のPOSTリクエスト?
私は認証のためのJWTであり、したがって私のトークンを渡す必要があります。
$response = $this->call('POST', 'users/?token=' . $this->token, $user);
しかし、それはのように私にリダイレクトを与えている:
$response = $this->call('GET', 'users?token=' . $this->token);
しかし、私は新しいユーザーまたはそのことについては、リソースを作成する必要があるときに、私がやろうとしています:シンプルなGETリクエストは簡単ですそう:私はいくつかの掘削をしたとき
<!DOCTYPE html>\n
<html>\n
<head>\n
<meta charset="UTF-8" />\n
<meta http-equiv="refresh" content="1;url=http://localhost" />\n
\n
<title>Redirecting to http://localhost</title>\n
</head>\n
<body>\n
Redirecting to <a href="http://localhost">http://localhost</a>.\n
</body>\n
</html>
は今、私はこれに出くわした:
Redirect 302 on Laravel POST request
とコールメソッドのAPIはそうのようになります。
$response = $this->call($method, $uri, $parameters, $cookies, $files, $server, $content);
だから私はこの試みた:
$response = $this->call('POST', 'users/?token=' . $this->token, $user, [], [], [], ['Content-Type' => 'application/x-www-form-urlencoded']);
をしかし、私はまだリダイレクトを取得しています。私は何が欠けていますか?
私は 'HTTP_Authorization'ではなく' Authorisation'を試みていました。とにかく、私は今も同じことを試みました。 $ this-> token、$ user、[]、[]、[]、['HTTP_Authorization' => 'Bearer'です。 $ this-> token]); ' – Rohan
完全なURIで試してみてください。 – Hoosk
同じです。さらに、テストルートで試して、 'request() - > header()'をダンプして、すべてのヘッダーを表示しました。 'content-type ':[" application \/x-www-form-urlencoded "]'は存在しますが、そこには 'HTTP_Authorization'ヘッダーはありません。 – Rohan