我想從DialMyCalls數據庫中提取數據並向其中添加數據。他們給我發了一些代碼,我找到了我的API密鑰,但我不知道如何連接它。我將PHP代碼上傳到我的服務器上,並嘗試運行它,但沒有得到任何結果,因爲我不確定要編輯什麼。我知道我需要編輯我假設的「空白」區域,但我不完全確定。歡迎任何幫助。DialMyCalls我在哪裏放API密鑰
這裏是他們發給我的代碼,所以如果你能告訴我要從他們的數據庫中提取信息要編輯什麼,我將不勝感激。謝謝。再次
<?php
class RestRequest
{
protected $url;
protected $verb;
protected $requestBody;
protected $requestLength;
protected $apikey;
protected $acceptType;
var $responseBody;
protected $responseInfo;
public function __construct ($apikey = null) {
$this->url = null;
$this->verb = null;
$this->requestBody = null;
$this->requestLength = 0;
$this->apikey = $apikey;
$this->acceptType = 'application/json';
$this->responseBody = null;
$this->responseInfo = null;
}
public function flush()
{
$this->requestBody = null;
$this->requestLength = 0;
$this->verb = 'POST';
$this->responseBody = null;
$this->responseInfo = null;
}
public function execute ($url = null, $verb = 'POST', $requestBody = null) {
$ch = curl_init();
$this->url = "https://www.dialmycalls.com/api".$url;
$this->verb = $verb;
$this->requestBody = $requestBody;
try
{
switch (strtoupper($this->verb))
{
case 'POST':
$this->doExecute($ch);
break;
default:
throw new InvalidArgumentException('Current verb (' . $this->verb . ') is an invalid REST verb.');
}
}
catch (InvalidArgumentException $e)
{
curl_close($ch);
throw $e;
}
catch (Exception $e)
{
curl_close($ch);
throw $e;
}
}
protected function doExecute (&$curlHandle) {
curl_setopt($curlHandle, CURLOPT_POST, 1);
$this->requestBody["apikey"] = $this->apikey;
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $this->requestBody);
// curl_setopt($curlHandle, CURLOPT_TIMEOUT, 60);
curl_setopt($curlHandle, CURLOPT_URL, $this->url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_VERBOSE, 0);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array ('Accept: ' . $this->acceptType,'Expect:'));
$this->responseBody = curl_exec($curlHandle);
$this->responseInfo = curl_getinfo($curlHandle);
curl_close($curlHandle);
}
}
?>
感謝您的幫助, 馬特
[需要幫助使用PHP與服務器通信](http://stackoverflow.com/questions/16135942/need-assistance-using-php-to-communicate-with-servers) – halfer 2013-04-27 11:14:19