Webtrends API 身份验证 PHP
我正在尝试使用 PHP 连接到 Webtrend 的 API,但无法进行身份验证。
WT 文档中给出的示例适用于 .NET 或 Ruby,.Net 示例如下:
var svc = new WebClient();
svc.Credentials = new NetworkCredential("yourWebTrendsAccount\WebTrendsUserName", "yourSuperSecretPassword");
svc.DownloadStringCompleted += svc_DownloadStringCompleted;
svc.DownloadStringAsync(new Uri(baseUri));
我不熟悉 .NET,但是 PHP 上是否有与 WebClient 类等效的类?
我一直在尝试使用 CURL 进行身份验证,
username = "my_account_name/my_login_name"
password = "my_password"
但到目前为止还没有成功。我收到一条错误消息,指出参数不正确。
更新:添加代码
$username=urlencode('my_account_name\my_login_name');
$password="my_password";
$postdata="username=$username&password=$password";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,"https://ws.webtrends.com/v2/ReportService/profiles/XXXXXXXX/reports/XXXXXXXX/?totals=all&period=2011w14&format=xml");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close($ch);
var_dump($result);
我也尝试过
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
,但到目前为止还没有运气。
I am trying to connect to Webtrend's API using PHP but haven't been able to authenticate.
The example given on the WT's documentation is for .NET or Ruby, the .Net example is like this:
var svc = new WebClient();
svc.Credentials = new NetworkCredential("yourWebTrendsAccount\WebTrendsUserName", "yourSuperSecretPassword");
svc.DownloadStringCompleted += svc_DownloadStringCompleted;
svc.DownloadStringAsync(new Uri(baseUri));
I am not familiar with .NET, but is there an equivalent of that WebClient class on PHP?
I have been trying to authenticate using CURL using
username = "my_account_name/my_login_name"
password = "my_password"
but so far no luck. I get an error message saying that the parameters are not correct.
Update: adding code
$username=urlencode('my_account_name\my_login_name');
$password="my_password";
$postdata="username=$username&password=$password";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,"https://ws.webtrends.com/v2/ReportService/profiles/XXXXXXXX/reports/XXXXXXXX/?totals=all&period=2011w14&format=xml");
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close($ch);
var_dump($result);
I also tried
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
but no luck so far.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你必须使用 CURLOPT_USERPWD 而不是 postdata:
I think you have to use CURLOPT_USERPWD instead of postdata:
@Kevin Horst 提供了一个使用curl 和PHP 执行基本身份验证请求的好示例。我经常需要通过命令行来执行此操作。为此,您需要在系统上安装curl。
根据 WebTrends 数据提取 API 的文档。他们使用基于 SSL 的基本身份验证,这是 RESTful 身份验证的标准。
WebTrends 数据提取 API
@Kevin Horst provided a good example of executing a basic authentication request with curl and PHP. I often need to do this via the command line. To do this you need curl installed on your system.
According to the documentation on the WebTrends Data Extraction API. They use Basic Authentication over SSL which is a standard for RESTful authentication.
WebTrends Data extraction API