PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 18, 2022

[FIXED] How to pass -d (Data) via a symfony curl post request

 October 18, 2022     curl, php, symfony     No comments   

Issue

I was wondering if anyone could point me in the right direction. We setup an api that will take a curl request such as

curl -X 'POST' 'url target' -H 'accept: application/json' -H 'Content-Type: application/x-www-form-urlencoded' -d 'username=some_user_name&password=some_password

Trying to write ethe request in symfony 6, it seems like i'm setting it up wrong and not placing the -d data into the correct area. It doesn't appear to go into the user_data field as i get an error 422 back from the server.

$response = $this->client->request('POST', $url_target, [
            'headers' => [
                'Accept' => 'application/json',
                'Content-Type' => 'application/x-www-form-urlencoded',
            ],
            'verify_peer' => false,
            'verify_host' => false,
            'data' => 'username=some_user_name&password=some_password'
        ]);

I was wondering if someone could point me in the right direction as i'm pretty sure i'm doing something stupid.


Solution

You need to pass your data in the body parameter:

$response = $this->client->request('POST', '', [
     // other params ...
    'body' =>  ['username' => 'some_user_name', 'password' => 'some_password']
   ]
);


Answered By - Harvey Dent
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing