Laravel POST请求API回答

时间:2018-05-03 17:41:55

标签: laravel api post laravel-5

我有一个Laravel应用程序,它应该向WebUntis API发送带有参数的POST请求,并且响应应该是会话ID。我可以发送一个POST请求,我得到一个答案,但我没有得到会话密钥。我已经测试了Postman中的代码,并且在那里工作。

路线/ api.php

Route::get('auth', 'UntisController@auth');

UntisController.php

class UntisController extends Controller
{

  public function auth()
  {

    $client = new \GuzzleHttp\Client();
    $req = $client->post( 'https://asopo.webuntis.com/WebUntis/jsonrpc.do?school=htblva_villach',[

                "id" => 8294829,
                "method" => "authenticate",
                "params" => [
                    "user" => "USERNAME",
                    "password" => "PASSWORD",
                    "client" => "web"
                ],
                "jsonrpc" => "2.0"
    ],
    ['Content-Type' => 'application/json'
    ]);



    dd($req);
  }
}

the response I get with POSTMAN, the respones i want

my Postman request

The response I get from my code

我已经尝试了

   dd($req->getBody());

但是我没有得到我想要的sessionid。

0 个答案:

没有答案