添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
发呆的面包  ·  使用 Java 上传 Blob - ...·  10 月前    · 
满身肌肉的高山  ·  Spring Boot 1.0 && ...·  1 年前    · 
逃跑的高山  ·  C 内存管理 | 菜鸟教程·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams 'cliend_id' => 'SOMEID', 'client_secret' => '9999jjjj67Y0LBLq8CbftgfdreehYEI=', 'grant_type' => 'client_credentials' $res = json_decode($res->getBody()->getContents(), true); dd($res); catch (GuzzleHttp\Exception\ClientException $e) { $response = $e->getResponse(); $result = json_decode($response->getBody()->getContents()); return response()->json(['data' => $result]);

as a responde I got message:

{"data":{"error":"invalid_clientId","error_description":"ClientId should be sent."}}

Now when I try to run the same url with same data in POSTMAN app then I get correct results:

What is bad in my code? I send correct form_params also I try to change form_params to json but again I got the same error...

How to solve my problem?

The problem is that in Postman you're sending the data as a form, but in Guzzle you're passing the data in the 'json' key of the options array.

I bet that if you would switch the 'json' to 'form_params' you would get the result you're looking for.

$res = $client->post('http://example.co.uk/auth/token', [
    'form_params' => [
        'client_id' => 'SOMEID',
        'client_secret' => '9999jjjj67Y0LBLq8CbftgfdreehYEI=',
        'grant_type' => 'client_credentials'

Here's a link to the docs in question: http://docs.guzzlephp.org/en/stable/quickstart.html#sending-form-fields

Also, I noticed a typo - you have cliend_id instead of client_id.

Just for the sake of clean code: You could use the RequestOptions::FORM_PARAMS constant instead of writing the array key in a string yourself. – WhySoToxic Apr 8, 2022 at 9:36

if you are using Http Client try the asForm method to pass data in x-www-form-url-encoded form

exact syntax

Http::asForm()->post('demo.com');
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.