0
我已经创建了一个能够连接到Azure Web服务的应用程序。但是,我希望能够通过浏览器访问数据。我想为此创建一个PHP站点,而不是使用邮递员。如何从PHP访问Azure移动应用程序服务?
尽管无法从外部网络访问数据库(并且我不打算更改此数据库),但我想使用该应用程序用于查询的相同访问点,即Azure移动应用程序。 (通过http:// {...} .azurewebsites.com/tables/{...})
我已经做了一些研究,有人建议使用cURL来处理这个问题。我已经建立了一些代码:
<?php
function CallAPI($method, $url, $data = false, $authenticate = false, $username = "", $password = "")
{
// Initializing cURL
$curl = curl_init();
// Setting headers
curl_setopt($curl, CURLOPT_HTTPHEADER, Array('ZUMO-API-VERSION: 2.0.0.', 'Accept: application/json', 'Cache-Control: no-cache'));
// Set actions based on method
switch($method)
{
case "POST":
curl_setopt($curl, CURLOPT_POST, 1);
if($data)
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($curl, CURLOPT_PUT, 1);
break;
default:
if($data)
$url = sprintf("%s?%s", $url, http_build_query($data));
}
// Authentication
if($authenticate)
{
$auth_string = $username.":".$password;
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $auth_string);
}
// Prepare execution
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Execution
$result = curl_exec($curl);
// Cleanup
curl_close($curl);
return $result;
}
// $url = "http://•••.azurewebsites.net/tables/users";
$result = CallAPI("GET", $url);
echo $result;
?>
然而,当我尝试执行此,我只得到这个答复:
{"error":"An invalid API version was specified in the request, this request needs to specify a ZUMO-API-VERSION of 2.0.0."}
我如何把头部正确地让我得到一个合适的回答?预先感谢您的帮助。