Creating a generalized HTTP Authentication function [closed]

喜夏-厌秋 提交于 2019-12-13 09:08:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!