0

I am using a curl method for getting the response in laravel. And after that I decode the response data and send on view page from the controller but I got the error -

Submitted URI too large!

My code is here on detailController.php-

public function details(Request $request)
    {

$json_data = array('requested data on array');          
$data_json = json_encode($json_data);           
$curl = curl_init();
curl_setopt_array($curl, array(
            CURLOPT_URL => "url where we send the request",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 20,
            CURLOPT_TIMEOUT => 50,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "POST",
            CURLOPT_POSTFIELDS => $data_json,
            CURLOPT_HTTPHEADER => array(
                    "accept: application/json",
                    "api-key: key provided from url",
                    "cache-control: no-cache",
                    "content-type: application/json"
                  ),
                ));

$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "error";           } 
else {
$getdetails = json_decode($response, true);
return view('viewpageurl', compact('getdetails'));
}           
}

viewpageurl.blade.php

@if($getdetails)            
 @foreach($getdetails as $getname)
  <h2>{!! $getname->details->name !!}</h2>
 @endforeach
@endif
Renu
  • 91
  • 1
  • 1
  • 10
  • 1
    Your answer is here (https://stackoverflow.com/questions/2891574/how-do-i-resolve-a-http-414-request-uri-too-long-error) – TeachMe May 26 '19 at 12:44
  • I want to get the response data through a POST method not a GET method.Please provide me solution for this if any. – Renu May 26 '19 at 16:16
  • I can't find this syntax in the documentation: `return view('viewpageurl','POST',compact('getdetails')); ` I don't see why you would pass a POST parameter to a view anyway. That should be in your routes, probably web.php. So you should have just `return view('viewpageurl',compact('getdetails'));` I don't know if this by itself will solve your problem. You might also have to change your Route::get route into a Route::post route in your web.php. It would be useful also if you post your routes file. – kaan_a May 26 '19 at 17:51
  • I already provided the post method on route file web.php.My problem is that when i am sending the response data on view page this response returns using get method.so i got error for big url.i want to send the response by using post method. – Renu May 26 '19 at 17:59

0 Answers0