Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request body converted the params into string type causing wrong response as compare to network request using fetch (React native) #6328

Closed
Suri-cbl opened this issue Mar 27, 2024 · 1 comment

Comments

@Suri-cbl
Copy link

Suri-cbl commented Mar 27, 2024

Describe the bug

Hey folks , I am not getting desired response from a POST api request with axios . Please check the code snippet below

const rawData = [56438] const accessToken = storage.getToken(); method:'POST', headers, }); return axiosInstance.post<ResponseAgingAnalysis>(endpoints.agingAnalysis,rawData)

Same request working with fetch 

What I observed axios request converted the body into string like this 

`0: "56438"`

but in fetch request raw data is in number type 

0: 56438

headers.append('Authorization',Bearer ${accessToken}); headers.append('Content-Type', 'application/json; charset=utf-8'); return fetch('url',{body: JSON.stringify(rawData), method:'POST', headers, });

To Reproduce

No response

Code snippet

const rawData = [56438]
    const accessToken = storage.getToken();
   method:'POST', headers,  });
    return axiosInstance.post<ResponseAgingAnalysis>(endpoints.agingAnalysis,rawData)

Expected behavior

I want request body should be same without type conversion .

Axios Version

1.6.7

Adapter Version

No response

Browser

No response

Browser Version

No response

Node.js Version

20

OS

No response

Additional Library Versions

"react-native": "0.73.5",
"react": "18.2.0",

Additional context/Screenshots

No response

@Suri-cbl
Copy link
Author

Fixed.

Issue: Wrong headers being sent in the request . Content-Type':'application/x-www-form-urlencoded'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant