创建通用的HTTP身份验证功能 [英] Creating a generalized HTTP Authentication function

查看:93
本文介绍了创建通用的HTTP身份验证功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的脚本登录以获取xml数据.是否可以使用相同的登录脚本,但是在需要时更改$oPMainUrl?

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

当前API登录名:

$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;

推荐答案

HTTP基本身份验证非常简单.您只需将凭证添加到每个请求.没有会话,每个请求都需要认证.

HTTP basic auth is dead simple. You just need to add the credentials to every request. There is no session, each request requires authentication.

这篇关于创建通用的HTTP身份验证功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆