Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // set up the URL value involved in a variable
- $url = "http://code.example.com:3343/csvn/api/1/user?format=json";
- // administrative user for API access
- $username = 'grundlett';
- $password = 'secret-words';
- // set up the data that is going to be passed
- $data = array(
- array(
- "username" => "example1",
- "password" => "mysecret",
- "fullName" => "Example Uno",
- "emailAddress" => "info@example.com"
- )
- );
- $jsonData = json_encode($data);
- echo "We're going to send this data\n";
- print_r ($jsonData);
- // exit();
- // perform the curl transaction
- $ch = curl_init();
- curl_setopt ($ch, CURLOPT_URL, $url);
- curl_setopt ($ch, CURLOPT_USERPWD, $username . ":" . $password);
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt ($ch, CURLOPT_POST, true);
- curl_setopt ($ch, CURLOPT_POSTFIELDS, $jsonData);
- // curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
- curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/json"));
- $response = curl_exec($ch);
- $decode = json_decode($response);
- print_r($decode);
- ?>
- ///////////////////////////////////////////////////////
- ///////////////// run it //////////////////////////////
- php -f example.php
- ///////////////// results / output ////////////////////
- We're going to send this data
- [{"username":"example1","password":"mysecret","fullName":"Example Uno","emailAddress":"info@example.com"}]
- stdClass Object
- (
- [errorMessage] => Bad request (check parameters)
- [errorDetail] => The email address entered is in an invalid format
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement