簡體   English   中英

API 適用於 postman 但不適用於 React 中的 axios

[英]API works in postman but not with axios in React

這是我的 API 電話:使用 postman它在 postman 中工作正常但是當我嘗試使用 axios

export const getAccountBalance = (id) => async (dispatch, getState) => {
    try {
        dispatch({
        type: BALANCE_FETCH_REQUEST,
        });
    
        const {
        userLogin: { userInfo },
        } = getState();
    
        const config = {
        headers: {
            "Content-Type": "application/json",
            Authorization: `Bearer ${userInfo.token}`,
        },
        };
        const { data } = await axios.get(`getAccountByAccountNo?accountNo=${id}`,config);
        console.log(data);
        dispatch({
            type: BALANCE_FETCH_SUCCESS,
            payload: data,
        });
    } catch (error) {
        dispatch({
            type: BALANCE_FETCH_FAIL,
            payload:
            error.response && error.response.data.message
                ? error.response.data.message
                : error.message,
        });
    }
};

它完全相同 URL 但它給出 404 not found 404 not found響應

請幫助我,我必須提交這個大學項目!!

謝謝

需要訪問絕對路徑 url

const { data } = await axios.get(`http://localhost:6969/v1/api/getAccountByAccountNo?accountNo

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM