使用Curl在PHP中使用用户名和密码访问API

时间:2017-06-27 02:16:47

标签: php json url zendesk-api

我需要你的帮助......我如何在php上查询它 这是示例代码,但在cmd上使用Curl

https://www.zopim.com/api/v2/chats -u {username}:{password}

谢谢..

1 个答案:

答案 0 :(得分:1)

也许会在How to use basic authorization in PHP curl上回答 所以试试吧:

val conf = sc.hadoopConfiguration 
conf.set("fs.defaultFS", "hdfs://some-path")

val hdfs: org.apache.hadoop.fs.FileSystem = org.apache.hadoop.fs.FileSystem.get(conf)

...

打印或显示json使用:

<?php
$username='username';
$password='pass';
$URL='https://www.zopim.com/api/v2/chats';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result=curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);   //get status code
curl_close ($ch);