首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel桌面应用程序

Laravel桌面应用程序
EN

Stack Overflow用户
提问于 2021-11-01 11:03:11
回答 1查看 60关注 0票数 1

我已经构建了laravel桌面应用程序,我正在使用api从实时服务器获取数据,它工作得非常好,但当我尝试使用api将数据从桌面应用程序上传到实时应用程序时,它不起作用,甚至没有显示任何错误。当我运行与web版本相同的代码时,它工作得非常好。我使用curl将数据从laravel桌面应用程序上传到live server数据库。这是我的curl

代码语言:javascript
复制
$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;

上面提到的代码用于将数据从laravel桌面应用程序上传到live server数据库。请为我引路,提前谢谢

EN

回答 1

Stack Overflow用户

发布于 2021-11-02 07:25:08

谢谢,它运行时添加了

代码语言:javascript
复制
 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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69795991

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档