Skip to content

Instantly share code, notes, and snippets.

@ohvitorino
Created August 10, 2017 07:19
Show Gist options
  • Save ohvitorino/925e6f805d64e67bffb4678612897bf8 to your computer and use it in GitHub Desktop.
Save ohvitorino/925e6f805d64e67bffb4678612897bf8 to your computer and use it in GitHub Desktop.
This a example of a curl request with basic authentication and x-www-form-urlencoded.
<?php
$curl = curl_init();
$header = [];
$header[] = 'Content-type: application/x-www-form-urlencoded';
// user:password in base64
$header[] = 'Authorization: Basic xxxxxx';
curl_setopt($curl, CURLOPT_URL, 'http://url/user/add');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POST,true);
curl_setopt($curl, CURLOPT_POSTFIELDS, 'id=888&email=xpto%40xpto.io&firstName=jonh&lastName=doe');
$response = curl_exec($curl);
curl_close($curl);
var_dump($response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment