I have these,
curl -v -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3N0YWdlLmlkcC5zYWRkbGViYWNrLmNvbS8iLCJhdWQiOiJod42RwOi8vbXlvbmxpbmVzbWFsbGdyb3VwLmNvbS8iLCJuYmYiOjEzODA1NjE1NzYsImV4cCI6MTM4MDU2NTE3Nn0.frMpom25eD2ls0UQh8Jk86bbXv5SOextRdQQfJuOboY" http://stage.api.test.com/Individual?id=1
So how to code this using PHP CURL?
Also I’m not sure the -v and -H option of the CURL above?, Is that the JAVA CURL option?
Thanks in advance.
solidcodes:
I have these,
curl -v -H "" http://stage.api.test.com/Individual?id=1
So how to code this using PHP CURL?
Also I’m not sure the -v and -H option of the CURL above?, Is that the JAVA CURL option?
Thanks in advance.
Curl -H is the header and -v is just verbose mode. So essentiall you just need a way to set the header in curl:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://stage.api.test.com/Individual?id=1");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL3N0YWdlLmlkcC5zYWRkbGViYWNrLmNvbS8iLCJhdWQiOiJod42RwOi8vbXlvbmxpbmVzbWFsbGdyb3VwLmNvbS8iLCJuYmYiOjEzODA1NjE1NzYsImV4cCI6MTM4MDU2NTE3Nn0.frMpom25eD2ls0UQh8Jk86bbXv5SOextRdQQfJuOboY'
));
if(curl_error($ch)) throw new exception(curl_error($ch));
print curl_exec($ch);
curl_close($ch);
@K . Wofe ;
Very very helpful dude.
I have another Java Curl codes I guess,
curl -u lms:09U1bx6qqHWW8MCIyjQi https://stage.idp.sample.com/issue/simple/?realm=http%3A%2F%2Fmyonlinesmallgroup.com%2F
So what is -u ?
And how to do that in PHP curl?
Okay I get it now, It means,
u: This specifies the user and password
I have another questions,
I have these codes below, and it authenticate the username and password of a user.
function curl_auth() {
$url = "https://stage.idp.samplesite.com/issue/simple/?realm=http%3A%2F%2Fmyonlinesmallgroup.com%2F";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// send the username and password
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
// if you allow redirections
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// this lets cURL keep sending the username and password
// after being redirected
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
$output = curl_exec($ch);
echo $output;
curl_close($ch);
}
So what happened if the username and password is correct?
What is the value of $output ?
Thanks in advance.
solidcodes:
I have another questions,
I have these codes below, and it authenticate the username and password of a user.
function curl_auth() {
$url = "https://stage.idp.samplesite.com/issue/simple/?realm=http%3A%2F%2Fmyonlinesmallgroup.com%2F";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// send the username and password
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
// if you allow redirections
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// this lets cURL keep sending the username and password
// after being redirected
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1);
$output = curl_exec($ch);
echo $output;
curl_close($ch);
}
So what happened if the username and password is correct?
What is the value of $output ?
Thanks in advance.
That depends entirely on the remote service and how they handle things like invalid credentials. One thing I see though is that you took out my function checking for curl_error($ch); You need this to capture things such as timeouts.