Skip to content

Instantly share code, notes, and snippets.

@mmilosheski
Last active December 1, 2016 11:14
Show Gist options
  • Save mmilosheski/53b0963a6845391eff8f42d264ddc353 to your computer and use it in GitHub Desktop.
Save mmilosheski/53b0963a6845391eff8f42d264ddc353 to your computer and use it in GitHub Desktop.
$username = $_POST['fs_username'];
$password = $_POST['fs_password'];
echo "<pre>";
var_dump("Username: ", $username, "Password: ", $password);
echo "</pre>";
$api_login_url = "https://servicesbeta.fidelitysalus.it/v3/account/login";
$login_response = wp_remote_retrieve_body(wp_remote_post( $api_login_url, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => array(
'SignInName' => $username,
'Password' => $password,
),
'cookies' => array()
)
));
echo "<pre>";
var_dump("Method 0: ", $login_response);
echo "</pre>";
$login_response1 = CallAPI("POST", $api_login_url, array('SignInName' => $username , 'Password' => $password ));
echo "<pre>";
var_dump("Method 1: ", $login_response1);
echo "</pre>";
// Method: POST, PUT, GET etc
// Data: array("param" => "value") ==> index.php?param=value
$login_response2 = wp_remote_retrieve_body( wp_remote_post( $api_login_url, array(
'httpversion' => '1.1',
'method' => 'POST',
'body' => array(
'SignInName' => $_POST['fs_username'],
'Password' => $_POST['fs_password'],
)
) ) );
echo "<pre>";
var_dump("Method 2: ", $login_response2);
echo "</pre>";
$login_response3 = wp_remote_retrieve_body( wp_remote_post( $api_login_url, array(
'method' => 'POST',
'body' => array( 'SignInName' => $username, 'Password' => $password ),
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( $username . ':' . $password ),
),
) ) );
echo "<pre>";
var_dump("Method 3: ",$login_response3);
echo "</pre>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$api_login_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$login_response4 = curl_exec($ch);
curl_close($ch);
echo "<pre>";
var_dump("Method 4: ",$login_response4);
echo "</pre>";
if ( is_wp_error( $login_response4 ) ) {
$error_message = $login_response4->get_error_message();
echo "Something went wrong: $error_message";
} else {
echo 'Response:<pre>';
print_r( $login_response4 );
echo '</pre>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment