duanliao6077 2011-05-16 07:39
浏览 38
已采纳

Webtrends API身份验证PHP

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.

  • 写回答

2条回答 默认 最新

  • dtv995719 2011-07-11 10:04
    关注

    @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.

     curl --user username:password \
    -i https://ws.webtrends.com/v2/ReportService/profiles/XXXXXXXX/reports/XXXXXXXX/?totals=all&period=2011w14&format=xml
    

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line