axios

Node.JS: Simple GET with axios module throwing “Error: Max redirects exceeded”

China☆狼群 提交于 2020-02-06 07:56:08
问题 Was trying to understand the basics of Web Scraping & was successful doing it with Python. When trying to emulate the same with Node getting following error : UnhandledPromiseRejectionWarning: Error: Max redirects exceeded. Below is simple code snippet that am trying to run using node scrape.js : const axios = require('axios'); const url = 'https://www.somewebsite.com/auth/get_menu/?city_id=1'; const headers = { 'accept': '*/*', 'content-type': 'application/json', 'app_client': 'consumer_web'

Vuex action which returns a promise never resolves or rejects

浪子不回头ぞ 提交于 2020-02-06 04:43:37
问题 I'm trying to build up my API service in my VueJS application by using Vuex. I'm in the process of refactoring some stuff to centralize error handling, clean-up, etc. The issue I'm running into is properly chaining Promises through my function calls. At the root level, I have a BaseService class, which simply make API requests using AXIOS (not full class): export abstract class BaseService { protected readonly API: AxiosInstance; // Full init left out protected deleteItem(url: string):

PHP does not execute function called via Axios in Vue.JS

一世执手 提交于 2020-02-06 03:45:12
问题 I am trying to write a Vue.JS module to do some data processing and send variables to a PHP functions in a seperate file. I'm using Axios to parse parameters to PHP. Now the problem is, the Axios request reaches the PHP file, but the PHP doesn't actually call the function that was intented to call. PHP call from Vue app: axios.post('./crmFunctions.php',{ params: { function2call:"sendQuery", id:1, mid:1, message: "Hello there!", event:"Query" }}) .then(response => this.responseData = response

How to send CSRF Cookie from React to Django Rest Framework with Axios

筅森魡賤 提交于 2020-02-04 01:41:24
问题 I want to make a POST request from a React app using Axios to a Django Rest Framework backend. I have managed to get a CSRF Token from the backend but I can't manage to send it with my request, so I always get a Forbidden (CSRF cookie not set.) error: This is the code of my React app: handleClick() { const axios = require('axios'); var csrfCookie = Cookies.get('XSRF-TOKEN'); console.log(csrfCookie) axios.post('http://127.0.0.1:8000/es/api-auth/login/', { next: '/', username: 'admin@admin.com'

Send object with axios get request [duplicate]

烂漫一生 提交于 2020-02-01 09:56:26
问题 This question already has answers here : Axios get in url works but with second parameter as object it doesn't (2 answers) Closed 2 years ago . I want to send a get request with an object. The object data will be used on the server to update session data. But the object doesn't seem to be sent correctly, because if I try to send it back to print it out, I just get: " N; " I can do it with jQuery like this and it works: $.get('/mysite/public/api/updatecart', { 'product': this.product }, data =

Axios Excel file download using POST results in corrupted file

谁都会走 提交于 2020-01-30 12:30:08
问题 I was using Axios to download a file provided by a GET endpoint previously. The endpoint has changed and is now a POST, however the parameters are not required. I'm updating the original download method, but am getting a corrupted file returned. downloadTemplate() { axios.post(DOWNLOAD_TEMPLATE_URL, { responseType: 'blob', headers: { 'Content-Disposition': "attachment; filename=template.xlsx", 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', } }) .then(

Logout if token is expired

99封情书 提交于 2020-01-30 08:19:30
问题 I'm working on a react application that consists of many API requests. The structure of the application is When logging in, I'm receiving a token on response and I'm saving the token in my local storage to be used in other API requests. This token is expired every 30 minutes and if I do an API request after 30 minutes, I'm receiving a status of 401 in my request. I'm using this 401 status to do my logging out and clearing token data in local storage. Example request export function

how to serialize parameters using axios

社会主义新天地 提交于 2020-01-30 07:51:10
问题 How would I serialize url parameters for use with axios? My parameters are just numbers in array [1,2] . Here is my code so far axios({ method: 'delete', url: '/api/' }) My request url will be something like this http://127.0.0.1:8000/api/?id=1&id=2 I looked at the paramsSerializer method that axios has but its confusing how it can be used or whether its even appropriate in my case. Please advice. Thanks 回答1: the config object of axios.get accepts params . In params you can specify your array

How to set X-Forwarded-For in Node.Js app while calling with axios

烈酒焚心 提交于 2020-01-25 06:45:13
问题 Okay, I just got an opportunity to work in nodejs, where I am using axios library to fetch the data from third party url. Everything was working very smoothly until it was deployed to staging ENV. Similar issue I got while working with rails, and the solution I found was to use @request['X-Forwarded-For'] = 'XX.YYY.Z.Z' in header. Coming to the issue now, have already tried options = { headers: { 'X-Forwarded-For': 'XX.YYY.Z.Z' } } and its not working at all even at local env :/ axios.get(URL

Enabled CORS in node/express but getting “Response to preflight request doesn't pass access control check”

*爱你&永不变心* 提交于 2020-01-25 06:08:10
问题 I am getting the error : Failed to load http://localhost:3000/users/register: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. On the front end i'm using axios: const instance = axios.create({ baseURL: 'http://localhost:3000', timeout: 1000, headers: {"Access-Control-Allow-Origin": "*"} }); instance.post('/users/register').then((res) =>