传递浏览器URL是否具有JSON正文请求URL?

时间:2018-07-28 05:23:12

标签: php url curl

我正在一个API项目中,其中JSON主体请求URL将是我的浏览器URL,用于将请求发送到另一个API,当我触发浏览器URL时,客户端将捕获具有相同值的三次而不是一次。

有人可以指导我我要去哪里哪里

浏览器URL http://domainverify.com/api.php?Name=name&Phone_number=1234567890&City=bangalore&Age=29&Occupation=salaried

已实现的代码:

   <?php
include('connection.php');



if(isset($_REQUEST['Phone_number']))
{
$mobile = $_REQUEST['Phone_number'];
$name = $_REQUEST['Name'];
$emailid = $_REQUEST['City'];
$age = $_REQUEST['Age'];
$occupation = $_REQUEST['Occupation'];

//$city = $_REQUEST['city'];
//$date = $_REQUEST['entered_date'];
//$callback = $_REQUEST['callback'];

echo "Phone_number=".$mobile.";";
echo "Name=".$name.";";
echo "City=".$emailid.";";
echo "Age=".$age.";";
echo "Occupation=".$occupation."";



//$mobile2 = substr($mobile, -10);
date_default_timezone_set('Asia/Kolkata');

$timestamp = time();
$date_time = date("d-m-Y H:i:s", $timestamp);

$query = "INSERT into `shortlead_db` (`name`, `phone_number`,`city`,`age`,`occupation`,`entered_date`) values ('$name', '$mobile','$emailid','$age','$occupation','$date_time')";
$result = mysqli_query($conn, $query);

if($result==true){

//echo $result;
//echo $query;
//echo "insrted";

$url1="http://23.281.132.19:8090/sendDataWithEncrypt";

//echo $url1;

$url12='http://domainverify.com/api.php';
$para='Name='.$name.'&Phone_number='.$mobile.'&City='.$emailid.'&Age='.$age.'&Occupation='.$occupation;
 //echo $para;


$ch = curl_init($url1);

//echo $ch;

$data['url'] = "$url12?$para";

echo "<pre>";

print_r($data);

$payload = json_encode($data,JSON_UNESCAPED_SLASHES);

echo $payload;
//echo $data;
//exit();
curl_setopt($curl, CURLOPT_POST, TRUE);
//attach encoded JSON string to the POST fields
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

//set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));

//return response instead of outputting
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//execute the POST request
$result = curl_exec($ch);

print_r($result);
//exit();
//curl_error;


//close cURL resource
curl_close($ch);
}

else{
    echo "Not inserted"; 
}
}
else
{
echo "Something went wrong";
}

?>

0 个答案:

没有答案