i’m using axios to send some queries to leetcode to access their graphql API. I’m using a chrome extension that reads the necessary cookie credentials so that i can use it as auth for the API. however, I’m getting Request failed with status code 499
errors as a response. my query and cookies work on postman, but it’s not working when i use axios. I’m not sure what postman is doing differently, but I’ll post my code here:
let url = `https://leetcode.com/graphql`;
const fetchSubmissionList = async (questionSlug) => {
let query = `
questionSubmissionList(
offset: 0,
limit: 20,
questionSlug: ${questionSlug}
) {
lastKey
hasNext
submissions {
id
title
titleSlug
status
statusDisplay
lang
langName
runtime
timestamp
url
isPending
memory
hasNotes
notes
}
}
}
`
chrome.storage.local.get(["LEETCODE_SESSION"]).then((result) => {
console.log("LEETCODE_SESSION - " + JSON.stringify(result));
setSession(result["LEETCODE_SESSION"])
document.cookie = `LEETCODE_SESSION=${result["LEETCODE_SESSION"]}; SameSite=None; Secure`;
chrome.storage.local.get(["csrftoken"]).then(async (result) => {
console.log("csrftoken - " + JSON.stringify(result));
setToken(result["csrftoken"])
document.cookie = `csrftoken=${result["csrftoken"]}; SameSite=None; Secure`;
await axios.post(
url, { query: JSON.stringify(query) },
{
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
withCredentials: true
}).then(res => res.json()).then(data => console.log(data))
});
});
}
i found some posts addressing this in other systems (like, nginx?), but not in axios. also, i read that this error stems from your client closing your connection too soon, but i don’t know how i can change that.
thanks
1
I'm not sure what postman is doing differently – postman doesn't require CORS response headers to work. A browser does. Sending CORS response headers in a request is not how CORS works
1 hour ago