问:我有一个大问题。我无法找到解决方案。数据通过 GET 通过表单提交。显然,然后通过 AJAX 重新加载结果。我已经通过 cURL 尝试了所有可能的方法。服务器甚至会抛出 SQL 错误消息。但不幸的是,我无法让它工作。谁能帮我?
#{
# "searchdata": {
# "required": "1",
# "statistics": "1",
# "offer_name": null,
# "zip": "01069",
# "location": null,
# "maxdistance": "5",
# "target_group": null,
# "age_group": null,
# "language": null,
# "sort": "zip_asc",
# "record_offset": 0
# }
#}
#Test-URL = https://pflegefinder.bkk-dachverband.de/aua/searchresult.php?searchdata%5Brequired%5D=1&searchdata%5Bstatistics%5D=1&searchdata%5Boffer_name%5D=&searchdata%5Bzip%5D=01069&searchdata%5Blocation%5D=&searchdata%5Bmaxdistance%5D=5&searchdata%5Btarget_group%5D=&searchdata%5Bage_group%5D=&searchdata%5Blanguage%5D=&searchdata%5Bsort%5D=zip_asc&searchdata%5Brecord_offset%5D=0
$data = array("required" => "1","statistics"=>"1","offer_name" => null,"zip" => "51143","location" => null,"maxdistance" => "20","target_group" => null,"age_group" => null,"language" => null, "sort" => "zip_asc", "record_offset" => 0);
$data_string = urlencode(json_encode($data));
$url = "https://pflegefinder.bkk-dachverband.de/aua/rest_searchresult.php?".date("U");
$ch = curl_init();
// set post fields
curl_setopt($ch, CURLOPT_URL, ($url));
# curl_setopt($ch, CURLOPT_HTTPHEADER, array('Cookie: MK_CookieConsent={"required":true,"statistics":true},PHPSESSID="6ldq1ffekjeum41gr3b4bp5tqm"'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
#curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
#curl_setopt($ch, CURLOPT_POSTFIELDS,'searchdata[required]=1&searchdata[statistics]=1&searchdata[offer_name]=&searchdata[zip]=01069&searchdata[location]=&searchdata[maxdistance]=5&searchdata[target_group]=&searchdata[age_group]=&searchdata[language]=&searchdata[sort]=distance_asc&searchdata[record_offset]=0');
curl_setopt($ch, CURLOPT_POSTFIELDS,array("searchdata"=>$data_string));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)');
curl_setopt($ch, CURLOPT_REFERER, 'https://pflegefinder.bkk-dachverband.de/aua/searchresult.php?searchdata%5Brequired%5D=1&searchdata%5Bstatistics%5D=1&searchdata%5Boffer_name%5D=&searchdata%5Bzip%5D=51143&searchdata%5Blocation%5D=&searchdata%5Bmaxdistance%5D=5&searchdata%5Btarget_group%5D=&searchdata%5Bage_group%5D=&searchdata%5Blanguage%5D=&searchdata%5Bsort%5D=distance_asc&searchdata%5Brecord_offset%5D=0');
# curl_setopt($ch, CURLOPT_REFERER, 'https://pflegefinder.bkk-dachverband.de/aua/');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_VERBOSE, '0');
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile2.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile2.txt");
curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
$seite = curl_exec($ch);
curl_close($ch);
答:laguage( 应该是的拼写错误language导致您看到的 SQL 错误。
我不再写太多 PHP,我使用 Insomnia HTTP 客户端输入您的请求,这就是我发现错误的方式。我导出了下面的代码,这对我很有用。
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://pflegefinder.bkk-dachverband.de/aua/rest_searchresult.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\n\t\"searchdata\": {\n\t\t\"required\": 1,\n\t\t\"offer_name\": null,\n\t\t\"zip\": 51143,\n\t\t\"location\": null,\n\t\t\"maxdistance\": 20,\n\t\t\"target_group\": null,\n\t\t\"age_group\": null,\n\t\t\"language\": null,\n\t\t\"sort\": \"zip_asc\",\n\t\t\"record_offset\": 0\n\t}\n}",
CURLOPT_COOKIE => "PHPSESSID=2a4tctjc0ec6potr1p5a0tonir",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}