-1

I have a API to a remote server and in the server I didn't have control, but test the API postman and OK, but in local: has been blocked by CORS policy.

I have this request for axios:

import React, { Component } from 'react'
import axios from 'axios';

export default class api_component extends Component {
  componentDidMount(){
    const apiKey = '#'; // Reemplaza con tu API Key

    // Configura los encabezados con la API Key
    const headers = {
      'Authorization': `Token ${apiKey}`,
      'User-Agent': 'PostmanRuntime/7.32.3',
      'Accept': '*/*',
      'Accept-Encoding': 'gzip, deflate, br',
      'Connection': 'keep-alive',
      'Host': '<calculated when request is sent>'

    };

    // Realizar una solicitud GET utilizando Axios con la API Key en los encabezados
    axios.get('https://api.nuovopay.com/dm/api/v1/devices.json', {
      headers: {
        headers: headers
      }
    })
      .then(response => {
        console.log('Response:', response.data);
      })
      .catch(error => {
        console.error('Error:', error);
      });
  }
  render() {
    return (
      <div>
        <h1>Hola mundo</h1>
      </div>
    )
  }
}

And if a test the api for postman that send ok status 200, but if i try do the request in axios in react send me this error: has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

How can i fix that?

I did an proxy server and a proxy reverse and that not funcion
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

0 Answers0