Home how to Call REST-API with post method in CURL from laravel 5.6?
Reply: 0

how to Call REST-API with post method in CURL from laravel 5.6?

user2262 Published in June 20, 2018, 10:43 pm

I am using laravel 5.6.I want to call REST-API with post method. where URL Parameter is JSON format. I simply called that API in Postman .where it is working. but when i try to call this Laravel Controller via CURL method then getting error

Array to string conversion

JSON Parameter is

 20","OrderNo":"1234","SOReference":"Test order",  
          {"CommentLine":"true","CommentText":"This is a comment line"},
                "Contents":"Fragile - do not drop"

My Laravel code is

        $curl = curl_init();
        curl_setopt_array($curl, array(
        CURLOPT_URL =>$request->url,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30000,
        CURLOPT_POSTFIELDS => $request->data,
        CURLOPT_HTTPHEADER => array(
            // Set here requred headers
            "accept: */*",
            "accept-language: en-US,en;q=0.8",
            "content-type: application/json",
            "Accept: application/json",
    $response = curl_exec($curl);
    $err = curl_error($curl);

This is Sample Image that being call from Postman. when i call this API directly then it is returning 200.

but when i try this from laravel then getting error . please check this image.

I try to use postman Generate code Snippets that images is below

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.3286 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO