简体   繁体   English

错误在请求的资源上没有“ Access-Control-Allow-Origin”标头

[英]Error No 'Access-Control-Allow-Origin' header is present on the requested resource

I'm trying to make a biometric authentication on a remote machine, using XMLHttpRequest. 我正在尝试使用XMLHttpRequest在远程计算机上进行生物特征认证。 But it is returning the following message: 但它返回以下消息:

XMLHttpRequest cannot load http://177.55.99.146:8080/autenticacao/autentica?arquivo=[object%20File] . XMLHttpRequest无法加载http://177.55.99.146:8080/autenticacao/autentica?arquivo=[object%20File] No 'Access-Control-Allow-Origin' header is present on the requested resource. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin ' http://www.yaratecnologia.com.br ' is therefore not allowed access 因此,不允许访问来源“ http://www.yaratecnologia.com.br

The code follows bellow .... Does anyone know where is the mistake? 代码如下。..有人知道错误在哪里吗? What should I do? 我该怎么办?

<?php
    // Allow from any origin
    if (isset($_SERVER['HTTP_ORIGIN'])) {
        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
        header('Access-Control-Allow-Credentials: true');
        header('Access-Control-Max-Age: 86400');    // cache for 1 day
    }

    // Access-Control headers are received during OPTIONS requests
    if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
            header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         

        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
            header("Access-Control-Allow-Headers:        {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");

        exit(o);
    }

    echo "You have CORS!";
?>

<script type="text/javascript">  
    function autenticarbiometria() { 
       var fileInput = document.getElementById('fileInput');
       var file = fileInput.files[0];
       var reader = new FileReader();
       var campo = "";
       var status = "f";;

       if (file.size != 400) {
          alert("ATENÇÃO --> O arquivo selecionado NÃO está em um formato Biométrico válido!");
          return false;
       }

       if (!confirm("CONFIRMA AUTENTICAÇÃO BIOMÉTRICA NA BASE DE DADOS?")) {
          return false;
       }

       if(window.XMLHttpRequest) {
          req = new XMLHttpRequest();
          }
       else if(window.ActiveXObject) {
          req = new ActiveXObject("Microsoft.XMLHTTP");
          }

       // Arquivo PHP juntamente com o valor digitado no campo (metodo GET)
       var url = "http://177.55.99.146:8080/autenticacao/autentica?arquivo="+file;

       // Chamada do metodo open para processar a requisicao

       req.open("GET",url,true);
       req.send(null); 

       // Quando o objeto recebe o retorno, chamamos a seguinte funcao
       req.onreadystatechange = function() {
         alert("Retorno do readyState == " + req.readyState + " readyStatus == " + req.status);
         if(req.readyState == 4 && req.status == 200) {
             // Resposta retornada pelo busca.php
             var resposta = req.responseText;
             alert("ATENÇÃO --> RETORNO AUTENTICACAO = " + resposta);
          }  
        }
  }
</script>

Your snippet is a little confusing. 您的摘要有些混乱。 If the whole code belongs to the same page, it seems like you have enabled CORS on you local machine, while the Access-Control-Allow-Origin must be set on the remote server you are autenthicating at. 如果整个代码都属于同一页面,则似乎您已在本地计算机上启用了CORS,而必须在您要使用的远程服务器上设置Access-Control-Allow-Origin

You should change the code on the remote server by setting the correct Access-Control-Allow-Origin header or, if that's not possible, you should perform the authentication from PHP (server-side). 您应该通过设置正确的Access-Control-Allow-Origin标头来更改远程服务器上的代码,或者,如果不可能,则应该从PHP(服务器端)执行身份验证。

暂无
暂无

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

相关问题 No 'Access-Control-Allow-Origin' header is present on the requested resource error - No 'Access-Control-Allow-Origin' header is present on the requested resource error 跨源资源错误:请求的资源上没有“Access-Control-Allow-Origin”标头 - Cross Origin Resource Error: No 'Access-Control-Allow-Origin' header is present on the requested resource Javascript-所请求的资源上没有“ Access-Control-Allow-Origin”标头 - Javascript - No 'Access-Control-Allow-Origin' header is present on the requested resource 请求的资源上不存在“Access-Control-Allow-Origin”标头 - No 'Access-Control-Allow-Origin' header is present on the requested resource 角度4-所请求的资源上没有“ Access-Control-Allow-Origin”标头 - Angular 4 - No 'Access-Control-Allow-Origin' header is present on the requested resource NodeJ在所请求的资源上不存在“ Access-Control-Allow-Origin”标头 - NodeJs No 'Access-Control-Allow-Origin' header is present on the requested resource Access-Control-Allow-Origin header 存在于请求的资源上 - Access-Control-Allow-Origin header is present on the requested resource 请求的资源 .htaccess 上不存在 Access-Control-Allow-Origin 标头 - No Access-Control-Allow-Origin header is present on the requested resource .htaccess XMLHttpRequest请求的资源上没有“Access-Control-Allow-Origin”标头 - XMLHttpRequest No 'Access-Control-Allow-Origin' header is present on the requested resource 请求的资源上不存在Access-Control-Allow-Origin标头 - Access-Control-Allow-Origin header is not present on the requested resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM