我正在研究php。我想将http
请求发送到ibeacon cloud&从云端检索一些数据想将它存储在mysql数据库中。
答案 0 :(得分:0)
尝试这样的事情:
<?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); ?>
}
答案 1 :(得分:0)
尝试下面的事情......
ws.url(url).setContentType("application/x-www-form-urlencoded")
.post("key1=value1&key2=value2");