问题
I am using the script below to login to get the xml data. Is there away that I can use the same login script but change the $oPMainUrl
when required?
HTTPS URI: https://domain.co.nz/file.xml
Current API Login:
$oPMainUrl = 'HTTPS URI';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $oPMainUrl);
curl_setopt($ch, CURLOPT_USERPWD, "username:pw");
$result = curl_exec($ch);
curl_close($ch);
$MainURI = simplexml_load_string($result);
$ID = $MainURI->property->agency_id;
回答1:
HTTP basic auth is dead simple. You just need to add the credentials to every request. There is no session, each request requires authentication.
来源:https://stackoverflow.com/questions/13132106/creating-a-generalized-http-authentication-function