简体   繁体   English

'Access-Control-Allow-Origin' header 包含多个值(Windows 上的 Plesk)

[英]The 'Access-Control-Allow-Origin' header contains multiple values (Plesk on Windows)

I have the following code in JS:我在 JS 中有以下代码:

// Function to feed the API
function FeedAPI() {
    // Define the API endpoint URL
    var apiUrl = "https://ifthenpay.com/api/gateway/paybylink/XXX-XXXX";

    // Define the JSON API body
    var apiData = {
        "id": "1234",
        "amount": ValueSelected(),
        "description": $('#name').val(),
        "lang": "en",
        "expiredate": "",
        "accounts": "",
        "selected_method": PaymentSelected()
    };
    console.log("API data: ", apiData);
    
    // Use jQuery's $.ajax() function to make the request
    $.ajax({
        type: "POST",
        url: apiUrl,
        data: JSON.stringify(apiData),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(response) {
            console.log("API response: ", response);
        },
        error: function(xhr, status, error) {
            console.error("Error: ", error);
        }
    });
}

But get this error: Access to XMLHttpRequest at 'https://ifthenpay.com/api/gateway/paybylink/XXX-XXXX' from origin 'https://example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed.但是出现此错误: Access to XMLHttpRequest at 'https://ifthenpay.com/api/gateway/paybylink/XXX-XXXX' from origin 'https://example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed.

I'm using Plesk on Windows and already tried to set my web.config file to the following:我在 Windows 上使用 Plesk,并且已经尝试将我的web.config文件设置为以下内容:

<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Headers" value="Content-Type" />
    <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
    <add name="Access-Control-Allow-Credentials" value="true" />
  </customHeaders>  
</httpProtocol>

At this point, I tried everything... Can someone help??在这一点上,我尝试了一切......有人可以帮忙吗?

So, I fixed my issue by just changinging the method of the API Integration to "GET".因此,我通过将 API 集成的方法更改为“GET”来解决我的问题。

Here is the code:这是代码:

function FeedAPI() {
// Define the API endpoint URL
var apiUrl = "https://ifthenpay.com/api/gateway/paybylink/get";

// Define the query parameters
var apiParams = {
    "gatewaykey": "XXX-XXXX",
    "id": "1234",
    "amount": ValueSelected(),
    "description": $('#name').val(),
    "lang": "en",
    "expiredate": "",
    "accounts": "XXX|YYY;MBWAY|XXX-XXXXX",
    "selected_method": PaymentSelected()
};

console.log("API params: ", apiParams);

// Use jQuery's $.ajax() function to make the request
$.ajax({
    type: "GET",
    url: apiUrl,
    data: apiParams,
    success: function(response) {
        console.log("API response: ", response);
        window.open(response.link, "_blank");
    },
    error: function(xhr, status, error) {
        console.error("Error: ", error);
    }
});
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CORS 策略错误:“Access-Control-Allow-Origin”标头包含多个值“*”、“*”,但只允许一个 - CORS policy error: The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed CORS 错误:对预检请求的响应 'Access-Control-Allow-Origin' header 包含多个值 '*、*'、 - CORS error: Response to preflight request The 'Access-Control-Allow-Origin' header contains multiple values '*, *', $ .post没有&#39;Access-Control-Allow-Origin&#39;标头 - $.post No 'Access-Control-Allow-Origin' header 没有“Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header Azure否&#39;Access-Control-Allow-Origin&#39;标头 - Azure No 'Access-Control-Allow-Origin' header 不存在“ Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present Access-Control-Allow-Origin&#39;标头包含多个值&#39;http://xx.xx.xx.xx:3002,http://xx.xx.xx.xx:3002&#39;,但只允许一个 - Access-Control-Allow-Origin' header contains multiple values 'http://xx.xx.xx.xx:3002, http://xx.xx.xx.xx:3002', but only one is allowed CORS – 跨域请求被阻止 – &#39;Access-Control-Allow-Origin&#39; 标头包含无效值 - CORS – Cross Origin Request Blocked – The 'Access-Control-Allow-Origin' header contains invalid value 在Access-Control-Allow-Origin标头中找不到源 - Origin not found in Access-Control-Allow-Origin header CORS标头“ Access-Control-Allow-Origin”丢失,但它出现在标头中 - CORS header 'Access-Control-Allow-Origin' missing but it present in the header
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM