axiosRequest header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers

I use Axios React PHP

First look at the Client code part

import axios from "axios"; 

export const logIn = (id, email, password) => {
    
    
    return (dispatch) => {
    
    
        const config={
    
    
            method:'post',
            url:'http://localhost/cup/cup.php',
            headers:{
    
    
                'Access-Control-Allow-Origin':'*',
            },
            data:{
    
    
                id:id,
                email:email,
                password:password
            }
        };

        axios.request(config).then((res) => {
    
    
            // console.log(res.data);
        });
  1. First of all, let me remind you to pay attention to this part of the code
  2. headers:{ 'Access-Control-Allow-Origin':'*',

Then look at the Server code part

<?php
include ("./conn.php");
header("Access-Control-Allow-Origin: *");

When we finish writing like this, we check the console and we will find
console error
server error

Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.

It's really weird! Why is there such a prompt? I have set up both on the client and server
Access-Control-Allow-Origin:*

So I went to Stack Overflow and checked all the resources, and the prompt still didn't work!

We have to taste this Access-Control-Allow-Origin- [Related Documents]

Access-Control-Allow-Origin is aResponse header
So I decided to delete all the headers in the client so that no error message will appear.

import axios from "axios"; 

export const logIn = (id, email, password) => {
    
    
    return (dispatch) => {
    
    
        const config={
    
    
            method:'post',
            url:'http://localhost/cup/cup.php',
            data:{
    
    
                id:id,
                email:email,
                password:password
            }
        };

        axios.request(config).then((res) => {
    
    
            // console.log(res.data);
        });

If anyone knows the relevant knowledge, please leave it to me, thanks dude Have a nice day!

Guess you like

Origin blog.csdn.net/weixin_43814775/article/details/107664449