Php 处理编码的服务器请求
访问我的服务器的iPhone应用程序发送以下JSON编码的请求: 所以“?”将被“%3F”替换 但现在,我的服务器似乎出了问题。如何在路由或控制器中处理此编码请求以正确处理 Routes.phpPhp 处理编码的服务器请求,php,swift,laravel,request,Php,Swift,Laravel,Request,访问我的服务器的iPhone应用程序发送以下JSON编码的请求: 所以“?”将被“%3F”替换 但现在,我的服务器似乎出了问题。如何在路由或控制器中处理此编码请求以正确处理 Routes.php Route::get('/aeds', 'AED\APIAEDController@index'); 控制器 public function index(Request $request) { // Get Latitude and Longitude from request url
Route::get('/aeds', 'AED\APIAEDController@index');
控制器
public function index(Request $request) {
// Get Latitude and Longitude from request url
$latitude = $request["latitude"];
$longitude = $request["longitude"];
$aeds = new AED();
// In no latitude and longitude is provided in request, search for all aeds
// If latitude and longitude is set in request, search for aeds in proximity of this location information
if(!isset($latitude) & !isset($longitude)) {
$aeds = $aeds->getAllAEDs();
$transformedAEDs = $this->respondWithCollection($aeds, new AEDTransformer);
// If no aeds are found return with error
if(!$aeds) {
$this->setStatusCode(404)->respondWithError("Keine AED in der Datenbank");
}
// Add meta information and merge the arrays
$meta = ['meta' => ['Heading 1' => 'H1', 'Heading 2' => 'H2']];
$response = array_merge($transformedAEDs, $meta);
return $this->setStatusCode(200)->respond($response);
} else {
$aeds = $this->searchAEDInRange($latitude, $longitude);
$transformedAEDs = $this->respondWithCollection($aeds, new AEDTransformer);
if (sizeof($aeds) == 0) {
$this->setStatusCode(404)->respondWithError("Keine AED in der Datenbank");
}
}
// Set Meta information and combine with data
$meta = ['meta' => ['Heading 1' => 'H1', 'Heading 2' => 'H2']];
$result = array_merge($transformedAEDs, $meta);
return $this->setStatusCode(200)->respond($result);
}
public function index(Request $request) {
// Get Latitude and Longitude from request url
$latitude = $request["latitude"];
$longitude = $request["longitude"];
$aeds = new AED();
// In no latitude and longitude is provided in request, search for all aeds
// If latitude and longitude is set in request, search for aeds in proximity of this location information
if(!isset($latitude) & !isset($longitude)) {
$aeds = $aeds->getAllAEDs();
$transformedAEDs = $this->respondWithCollection($aeds, new AEDTransformer);
// If no aeds are found return with error
if(!$aeds) {
$this->setStatusCode(404)->respondWithError("Keine AED in der Datenbank");
}
// Add meta information and merge the arrays
$meta = ['meta' => ['Heading 1' => 'H1', 'Heading 2' => 'H2']];
$response = array_merge($transformedAEDs, $meta);
return $this->setStatusCode(200)->respond($response);
} else {
$aeds = $this->searchAEDInRange($latitude, $longitude);
$transformedAEDs = $this->respondWithCollection($aeds, new AEDTransformer);
if (sizeof($aeds) == 0) {
$this->setStatusCode(404)->respondWithError("Keine AED in der Datenbank");
}
}
// Set Meta information and combine with data
$meta = ['meta' => ['Heading 1' => 'H1', 'Heading 2' => 'H2']];
$result = array_merge($transformedAEDs, $meta);
return $this->setStatusCode(200)->respond($result);
}