AMP Access Control Allow Source Origin header Issue

前端 未结 3 517
北荒
北荒 2020-12-09 22:38

How can I resolve the error below;

Failed to load resource: the server responded with a status of 500 (Internal Server Error) cdn.ampproject.org/v0.

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 23:17

    Please try with following code

    if(!empty($_POST)){
            $domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
            header("Content-type: application/json");
            header("Access-Control-Allow-Credentials: true");
            header("Access-Control-Allow-Origin: ". str_replace('.', '-','https://example.com') .".cdn.ampproject.org");
            header("AMP-Access-Control-Allow-Source-Origin: " . $domain_url);
            header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
            header("AMP-Redirect-To: https://example.com/thankyou.amp.html");
            header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin"); 
            echo json_encode(array('successmsg'=>'data post'));
            exit;
    }
    

    Please make sure that domain url should be https

    Replace https://example.com/ to your desired url

提交回复
热议问题