javascript 当我执行put操作时,axios返回ERR_NETWORK

6l7fqoea  于 2023-06-28  发布在  Java
关注(0)|答案(1)|浏览(153)

当我想把对象发送到Route时,axios会返回ERR_NETWORK。我不知道CORS是否被卷入。
Here I show you the error
My services.js:

import axios from "axios";

export const apiClient = axios.create({
    baseURL: 'https://laboratorio3-f36a.restdb.io/rest',
    headers: {'x-apikey': '60eb09146661365596af552f',
    'Access-Control-Allow-Headers' : '*',
    'Access-Control-Allow-Origin' : 'http://localhost:8080',
    'Access-Control-Allow-Credentials': '*',
    'Accept': 'application/json',
    },
    
    
});
export default{
    

    transaction(purchaseData){
        return apiClient.post(`/transaction/`, purchaseData)
    },
    getHistorial(id){
        return apiClient.get(`/transactions/${id}`)
    },
    delete(id){
        return apiClient.delete(`/transactions/${id}`)
    },
    edit(id){
        return apiClient.put(`/transactions/${id}`)
    }

}

这里我发送Object:

const Purchase = async () => {          
                console.log('Los datos son: ',purchaseData)
                
                try {
                    console.log('Enviando....')
                    await lab3api.transaction(purchaseData);
                    console.log('Enviaooouu')
                } catch(e) {
                    console.log("Error en la compra", e)
                }
        }

我试过安装cors库。我添加了标题Accessi-Control-Allow-Methods,但这也不起作用。我已经安装了一个扩展,据说允许CORS,等等,等等

alen0pnh

alen0pnh1#

是的,您必须获取ERR_network

{'Access-Control-Allow-Headers' : '*',
    'Access-Control-Allow-Origin' : 'http://localhost:8080',
    'Access-Control-Allow-Credentials': '*',
    'Accept': 'application/json',
    },

1.配置在axios阅读此文档获得您的答案
document for axios config

验证API端点:请确保您使用的baseURL正确且API可访问。您可以尝试直接在浏览器中访问API端点,或使用cURL或Postman等工具来确认服务器是否按预期响应。

相关问题