php curl post json

$ch = curl_init( $url );
# Setup request to send json via POST.
$payload = json_encode( array( "customer"=> $data ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);

3.9
10

                                    // set post fields
$post = [
    'username' => 'user1',
    'password' => 'passuser1',
    'gender'   => 1,
];

$ch = curl_init('http://www.example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

// execute!
$response = curl_exec($ch);

// close the connection, release resources used
curl_close($ch);

// do anything you want with your response
var_dump($response);

3.9 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
curl output as json php curl example php curl php send json body php curl post data example curl using php php curl return json php curl post json example simple curl get request php use curl in php php post request curl json curl in php example curl post raw json php curl i php php curl json body get json response in curl req php php curl post application/json curl php get json php curl data json php curl post json curl send json data php curl with json in body php request php curl return json curl php response json php curl post request with authentication php use curl to post api curl example in php curl call php curl function in php php make curl call php curl get example how to send curl get request php php curl post data php curl put php curl post parameters php post with curl CURL FROM PHP curl post string php curl to php curl to post php get curl in php php curl example curl in php send post request in curl php php curl post with parameters curl post request php using curl in php curl post url php curl php get POST data using cURL PHP php curl string how to do a curl request in php curl post data PHP php curl post example php make post request curl how to use curl post mehtod in php php curl call how to use curl in php get curl php curl php example php curl get curl send post php php curl php curl send post request curl php post curl php curl post api php send post request php curl php example post json curl_setopt post data curl post using php script php curl post request php curl request curl -d params curl post php post curl data php curl post php post curl php curl php post example php curl post
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source