1

i make a simple api which return some value but if i add this line and pass data like curl_setopt($cURLConnection, CURLOPT_POSTFIELDS , $data); my api return null here is the complete code

  $data = ['a' => "data"];

        $url = env('MOTHERSHIP_URL') . '/store/cstore/receipt';
        Log::debug("url=" . $url);
        $cURLConnection = curl_init();
        curl_setopt($cURLConnection, CURLOPT_URL, $url);
        curl_setopt($cURLConnection, CURLOPT_POST, true);
        curl_setopt($cURLConnection, CURLOPT_POSTFIELDS , $data);
        curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($cURLConnection, CURLOPT_SSL_VERIFYHOST, false);
                    
        $apiResponse = curl_exec($cURLConnection);
        curl_close($cURLConnection);
        $data = json_decode($apiResponse, true);

        dd($data);

route

Route::any('/store/cstore/receipt', 'CStoreController@StoreCstoreReceipt')->name('store.cstore.receipt');

controller

public function StoreCstoreReceipt(Request $request){

         Log::debug($request->all());
        return "Success";
     }

problem is if i add curl_setopt($cURLConnection, CURLOPT_POSTFIELDS , $data); api return null if dont add this line then it works fine what i am doing wrong? i also tried an other method but in this i am getting some html accept of getting response

Hamza
  • 124
  • 9

1 Answers1

0

Try curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($arr));

SEYED BABAK ASHRAFI
  • 4,093
  • 4
  • 22
  • 32