【发布时间】:2016-05-27 06:21:38
【问题描述】:
我正在研究 php。我想向 ibeacon 云发送http 请求并从云中检索一些数据并希望将其存储在 mysql 数据库中。
【问题讨论】:
-
您的确切问题是什么?你能解释一下你期望看到什么以及你现在得到什么吗?
-
函数是
curl_init()而不是curl init()。首先找出错误并尝试解决它们,或者至少写下您面临的问题。
我正在研究 php。我想向 ibeacon 云发送http 请求并从云中检索一些数据并希望将其存储在 mysql 数据库中。
【问题讨论】:
curl_init() 而不是curl init()。首先找出错误并尝试解决它们,或者至少写下您面临的问题。
试试这样的:
<?php include "connection.php";
$ch = curl_init();//instead of $ch = curl init();
curl_setopt($ch,CURLOPT_URL, "https://cloud.estimote.com/v1/beacons");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "achopra-smu-edu-sg-s-your iuw:10e891270177480e7443148908d0afa3");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json"));
$output = curl_exec($ch);
print_r($output);
//perform task based on response
$json=json_decode($output,true));//based on key available in response.
$major = $json['major'];
$battery = $json['battery'];
$AdvertisingInterval = $json['Advertising Interval'];
$BroadcastingPower = $json['BroadcastingPower'];
$value = "INSERT INTO
battery_level(major,battery,AdvertisingInterval,BroadcastingPower)VALUES('".$major."''".$battery."''".$AdvertisingInterval."''".$BroadcastingPower."')";
echo $value;
$result = mysqli_query($conn,$value);
if(!result) { die ("could not insert data : " . PHP_EOL.mysqli_connect_errno());
}else{
echo "Insert data successfully\n"; curl_close($ch); ?>
}
【讨论】:
$json=json_decode($output,true)) 解码输出,然后使用此数组插入。
{"error":"Unauthorized"},这意味着凭据错误。