1

I have built laravel desktop application and I'm using apis for fetching data from the live server and it is working absolutely fine but when ever i try to upload data from desktop application to live application with api it doesn't work and even does not show any error. when i run same code as web version its working absolutely fine i used curl to upload data from laravel desktop application to live server database here is my curl

$fixtures = Matche::withTrashed()->get();
    $matchOfficials = MatchOfficial::all()->groupBy('match_id');
    $matchPlayers = MatchPlayer::all()->groupBy('match_id');
    $matchDetails = MatchDetail::all()->groupBy('match_id');
    $points = Points::all();
    $teamRankings = RankingPoints::all();
    $followReports = FollowReport::all();
    $topKeepers = TopKeeper::all();
    $topScorers = TopScorer::all();
    $url = 'https://asianhandball.info/symbargo/api/push-fixtures';
    $token = csrf_token();
    $postData = array(
        'fixtures' => $fixtures,
        'matchOfficials' => $matchOfficials,
        'matchPlayers' => $matchPlayers,
        'matchDetails' => $matchDetails,
        'points' => $points,
        'teamRankings' => $teamRankings,
        'followReports' => $followReports,
        'topKeepers' => $topKeepers,
        'topScorers' => $topScorers
    );
    // for sending data as json type
    $fields = json_encode($postData);
    $ch = curl_init($url);
    curl_setopt(
        $ch,
        CURLOPT_HTTPHEADER,
        array(
            'Content-Type: application/json', // if the content type is json
            'bearer: ' . $token // if you need token in header
        )
    );
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);

    $result = curl_exec($ch);
    curl_close($ch);
    return $result;

the above mentioned code is used to upload data from laravel desktop application to live server database. Kindly guide me for this Thank you in advance

  • I’d check to see if the server is returning a non-success HTTP status code – Chris Haas Nov 01 '21 at 12:23
  • it gives me nothing just "false" but if i run the same code on browser it works absolutely fine – Abdur Rehman Alvi Nov 01 '21 at 12:48
  • Turn PHP and Laravel error reporting on, and check the logs. Many things above can return `false` above, including `curl_init` and `curl_exec`, please check every one of them. If the latter is returning `false`, call `curl_error` on the handle. And, as I set above, check the [HTTP status code](https://stackoverflow.com/a/28427868/231316) that is returned. – Chris Haas Nov 01 '21 at 13:34
  • thanks it runs with the addition in curl as i mentioned in the answer – Abdur Rehman Alvi Nov 02 '21 at 07:25

1 Answers1

0

Thanks it runs with the addition of

 curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);