1$ch = curl_init( $url );
2# Setup request to send json via POST.
3$payload = json_encode( array( "customer"=> $data ) );
4curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
5curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
6# Return response instead of printing.
7curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
8# Send request.
9$result = curl_exec($ch);
10curl_close($ch);
1curl -X POST -H "Content-Type: application/json" \
2 -d '{"username":"abc","password":"abc"}' \
3 https://api.example.com/v2/login
4
1# dont forget the content type, else it will throw an error
2
3curl -X POST -H "Content-Type: application/json" \
4 -d '{"username":"abc","password":"abc"}' \
5 https://api.example.com/v2/login
1curl -X POST -H "Content-Type: application/json" -d @../data/cats.json http://localhost:8080/mSfvMwNAfj
2
1curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"id":100}' http://localhost/api/postJsonReader.do