我已经构建了laravel桌面应用程序,我正在使用api从实时服务器获取数据,它工作得非常好,但当我尝试使用api将数据从桌面应用程序上传到实时应用程序时,它不起作用,甚至没有显示任何错误。当我运行与web版本相同的代码时,它工作得非常好。我使用curl将数据从laravel桌面应用程序上传到live server数据库。这是我的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;上面提到的代码用于将数据从laravel桌面应用程序上传到live server数据库。请为我引路,提前谢谢
发布于 2021-11-02 07:25:08
谢谢,它运行时添加了
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);https://stackoverflow.com/questions/69795991
复制相似问题