だから、コメントを待ち望んでいます。次のファイルproxy_loader.phpを作成し、Webサーバーのルートディレクトリ(通常はhttpdocs)に配置すると仮定します。https://domain.tdl/proxy_loader.phpからアクセスできる必要があります
ファイルは次のようになります。
<?PHP
// get the url provided by javascriot
$url= $_GET['url'];
// initialize CURL
$ch = curl_init();
// additional headers like session id etc.
$header = '';
// optional user & password
$userpass = 'user:password';
//$parameters for the request
// use parameter name as array key
// use parameter value as array value
$param = array();
// set url
curl_setopt($ch, CURLOPT_URL, $url);
//this enables the output into a variable
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// set optional header
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// set request method to GET
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
// optional http authenfication
// remove the // to enable
// curl_setopt($ch, CURLOPT_USERPWD, $userpass);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
// execute the request
// and save the response in $ret
$ret = curl_exec($ch);
// close the connection
curl_close($ch);
echo $ret;
// maybe you must use this:
// echo json_encode($ret);
?>
次のような関数を使用して、サーバー経由で URL をリクエストできます。
function check() {
var ENV_URL = 'http://../BlueLight/api/BlueLights/getActiveBlueLight';
$('#trBlueLight').hide();
$.getJSON('/proxy_loader.php?url=' + ENV_URL, function (data) {
if (data.expDate != null) {
$('#trBlueLight').show();
} else {
$('#trBlueLight').hide();
}
});
}