Comments (7)
could any body help me on this?
from use-http.
Are you seeing the headers in the network tab in devtools for the request?
from use-http.
Hi Alex, Thanks for replying to my issue, I can see headers but not the one I sent X-XSRF-TOKEN when I used useFetch but I can see this header when I am using Axios. Below images is from axios
Below is image is from use-http with useFetch hook.
from use-http.
It might be because of caching. Did you try cachePolicy: 'no-cache'
?
from use-http.
Hi Alex,
I tried adding cachePolicy but still same error (403), I am suspecting that use-http is not taking the headers I am passing on, not sure if the options I used is right way to pass the headers to use-http, do you have any example of post request with use-http and headers included?
from use-http.
const { ... } = useFetch('url-or-path', options => {
options.headers = {
/* your headers here */
}
return options
})
You could also do this. And if your url is set in the provider, you don't need to pass the url.
const { post } = useFetch({
headers: { ... }
})
post('/route', body)
Or you if you are making multiple different api calls from the single useFetch you could do
const { post } = useFetch({
interceptors: {
request({ request }) {
// if the URL is the exact one you want and method === 'POST', then add the headers to I believe `request.headers`
return request
}
}
})
from use-http.
Thanks for your the details, I added provider and implemented the global options with provider and that worked good. Thank you so much again. I would call it close this issue as it is answered.
const globalOptions = {
interceptors: {
// every time we make an http request, this will run 1st before the request is made
// url, path and route are supplied to the interceptor
// request options can be modified and must be returned
request: async ({ options}) => {
if(options.method==='POST'){
options.headers['X-XSRF-TOKEN']=csrfToken;
options.headers.Accept='application/json';
options.headers['Content-Type']='application/json';
}
return options
},
// every time we make an http request, before getting the response back, this will run
// response: async ({ response }) => {
// const res = response
// if (res.data) res.data = toCamel(res.data)
// return res
// }
}}
return (
from use-http.
Related Issues (20)
- function to overwrite global options don't update after dependency change HOT 6
- useFetch `post` call inserts quotes when passed a string HOT 6
- React Native and Cache
- [Feature Request] time denounce http get requests
- does useFetch have option for skip request?
- Data not populated at mount HOT 5
- React 18 StrictMode HOT 22
- `Error: Invalid hook call` after upgrading to React 18.1 HOT 1
- Interceptors aren't chained HOT 8
- Cannot abort delayed retries
- [Feature Request] A way to invalidate the cache HOT 1
- Upload File Progress
- can recall post when parameter change?
- does post can auto fire? HOT 2
- Eslint rule react-hooks/exhaustive-deps questions on having response as depency HOT 1
- React 18 not supported? HOT 1
- Following instructions in .github/contributing.md fails when using the latest React 18 HOT 2
- Initial URL with a trailing slash adds double slash on relative urls
- TS: Ability to add expected type for fetch body. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from use-http.