简体   繁体   中英

API works in postman but not with axios in React

Here is my API calls: using postman It works fine in postman but when I try using 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,
        });
    }
};

Its exactly the same URL but its giving 404 not found 404 not found response

Please help me, I have to submit this college project!!

Thank you

Need to access absolute url path

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM