【问题标题】:Wordpress wp_redirect CORS IssueWordPress wp_redirect CORS 问题
【发布时间】:2018-04-16 03:07:57
【问题描述】:

我在尝试使用 wordpress 结帐插件中的 wp_redirect() 方法重定向到外部 URL 以将 woocommerce 结帐与 PayU Latam php SDK 集成时遇到了麻烦。

此消息总是引发 CORS 问题

跨域请求被阻止:同源策略不允许读取位于https://lorem.ipsum.dolor.com.co/xxxxxxxxxxxx/StartTransaction.htm?enc=xxxxxxxx%xxxxxxx%xxxxxxxxx 的远程资源。 (原因:CORS 标头“Access-Control-Allow-Origin”缺失)。

重定向响应代码也为 200 但使用 OPTIONS 方法

这是我正在使用的代码

$response = PayUPayments::doAuthorizationAndCapture($parameters);
if ($response) {
if ($response->transactionResponse->state)
    if ($response->transactionResponse->state == "PENDING") {
        $response->transactionResponse->pendingReason;
        $response->transactionResponse->extraParameters->BANK_URL;
    }
$response->transactionResponse->responseCode;

$this->redirectURL = $response->transactionResponse->extraParameters->BANK_URL;
wp_redirect($this->redirectURL);
exit;
}

有人可以告诉我我错过了什么吗???非常感谢

【问题讨论】:

    标签: php wordpress woocommerce payu


    【解决方案1】:

    将以下代码放入您的 .htacess 中:

      <IfModule mod_headers.c>
       Header set Access-Control-Allow-Origin "*"
      </IfModule>
    

    【讨论】:

    • 感谢 Akshay Shah... 不幸的是,通过此设置,此行生成的请求 $response = PayUPayments::doAuthorizationAndCapture($parameters);没有任何响应,也没有触发重定向
    猜你喜欢
    • 2016-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-14
    • 2018-05-19
    • 2017-05-07
    • 1970-01-01
    • 2019-07-20
    相关资源
    最近更新 更多