<?php
in this part I provide a latitude a longitude to reverse geocode.
$ch = curl_init("http://maps.google.com/maps/api/geocode/json?latlng=39.784268,-98.393555&sensor=false");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($ch);
curl_close($ch);
$geoOutput = json_decode($return, true);
$data = current($geoOutput);
echo $data;
After that I want to pass the content to a servlet but for example purposes I embedded the street and zipcode.
The generated url is like the following, but if you run the url will not happen anything in curl. But if you copy paste the code in the browser will succed.
$urlse="http://136.145.116.30:8080/AccidentDetailsInserter?latitude=18.209&longitude=-67.139&frontal_damage=1&left_damage=1&right_damage=0&back_damage=0&smoke_detected=0&flipped=0&maxforce=7&roll=0&pitch=0&yaw=0&device_id=47&street=Calle Caobos&city= Mayagüez&state=PR&zip= 00680";
echo $urlse;
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$urlse);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
here the output is blank
?>
I tried to write to specify the port to 8080 but nothing.
Your second URL contains spaces and other unescaped characters that should be urlencoded. If you paste it in the browser the browser fixes that for you. CURL doesn’t.
instead of
street=Calle Caobosor other such parameters, you should sendstreet=Calle%20Caobos. just useurlencode()on all parameters you are building.Edit: there were a few things missing here, here is some working code: