axios

Axios posting params not read by $_POST

不羁的心 提交于 2019-11-27 09:02:41
So I have this code: axios({ method: 'post', url, headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, data: { json, type, } }) Originally I had the normal axios.post but I changed to this because I thought it might have been a header problem. However I am still detecting nothing in my $_REQUEST nor $_POST . However, it is receiving data in file_get_contents("php://input") . Any idea what is wrong? Edit Okay I think I know what's wrong. It's posting it as a json object so it can only be read in the php://input. How do I change it to a normal string in axios? From the documentation

use axios globally in all my components vue

我只是一个虾纸丫 提交于 2019-11-27 08:51:58
I am testing with axios within a Vue application and the CLI. I've been using vue-resource and I could access it on all my components by simply passing it to Vue.use (VueResource). How can I achieve this with axios, so I do not have to import it into a component, but simply define it once in the main.js file? In main.js you can just assign Axios to $http. main.js import Axios from 'axios' Vue.prototype.$http = Axios; By modifying the vue prototype, any vue instance will have the ability to call $http on this . (e.g. this.$http.get('https://httpbin.org/get') Note: $http is the axios object now,

How to send authorization header with axios

我只是一个虾纸丫 提交于 2019-11-27 06:57:01
How can I send an authentication header with a token via axios.js? I have tried a few things without success, for example: const header = `Authorization: Bearer ${token}`; return axios.get(URLConstants.USER_URL, { headers: { header } }); Gives me this error: XMLHttpRequest cannot load http://localhost:8000/accounts/user/. Request header field header is not allowed by Access-Control-Allow-Headers in preflight response. I have managed to get it work by setting global default, but I'm guessing this is not the best idea for a single request: axios.defaults.headers.common['Authorization'] = `Bearer

App Script sends 405 response when trying to send a POST request

ぐ巨炮叔叔 提交于 2019-11-27 06:53:36
问题 I have published an app script publicly (Anyone, even anonymous) with a doPost method as follow, function doPost(e){ var sheet = SpreadsheetApp.getActiveSheet(); var length = e.contentLength; var body = e.postData.contents; var jsonString = e.postData.getDataAsString(); var jsonData = JSON.parse(jsonString); sheet.appendRow([jsonData.title, length]); var MyResponse = "works"; return ContentService.createTextOutput(MyResponse).setMimeType(ContentService.MimeType.JAVASCRIPT); } When I sent a

How to download files using axios

自作多情 提交于 2019-11-27 06:37:55
I am using axios for basic http requests like get and post, and it works well. Now I need to be able to download excel files too. Is this possible with axios. If so does anyone have some sample code? If not what else can I use in a react application to do the same? When response comes with a downloadable file, response headers will be something like Content-Disposition: "attachment;filename=report.xls" Content-Type: "application/octet-stream" // or Content-type: "application/vnd.ms-excel" What you can do is create a separate component, which will contain a hidden iframe. import * as React from

CSRF with Django, React+Redux using Axios

别等时光非礼了梦想. 提交于 2019-11-27 06:37:34
This is an educational project, not for production. I wasn't intending to have user logins as part of this. Can I make POST calls to Django with a CSRF token without having user logins? Can I do this without using jQuery? I'm out of my depth here, and surely conflating some concepts. For the JavaScript side, I found this redux-csrf package. I'm not sure how to combine it with my POST action using Axios: export const addJob = (title, hourly, tax) => { console.log("Trying to addJob: ", title, hourly, tax) return (dispatch) => { dispatch(requestData("addJob")); return axios({ method: 'post', url:

Make Axios send cookies in its requests automatically

北战南征 提交于 2019-11-27 06:35:14
I am sending requests from the client to my Express.js server using Axios. I set a cookie on the client and I want to read that cookie from all Axios requests without adding them manually to request by hand. This is my clientside request example: axios.get(`some api url`).then(response => ... I tried to access headers or cookies by using these properties in my Express.js server: req.headers req.cookies Neither of them contained any cookies. I am using cookie parser middleware: app.use(cookieParser()) How do I make Axios send cookies in requests automatically? Edit: I set cookie on the client

How to use the axios library with AngularJS

我的未来我决定 提交于 2019-11-27 05:38:05
Why axios callback changes are displayed in angularjs, without using $apply I was trying axios library on angularjs and I was surprised when I saw that the changes to $scope in the axios callback were detected by angular. I thought I had to call $apply like, for example, when you use setTimeout . // axios example axios.get(url).then((response) => { // Here I don't need $apply, why?? $scope.axiosResult = response.data; }); // setTimeout example setTimeout(() => { // Here I need $apply for the timeoutResult to appear on the HTML $scope.$apply(() => $scope.timeoutResult = {message: "timeout!"});

Axios: chaining multiple API requests

佐手、 提交于 2019-11-27 05:32:59
问题 I need to chain a few API requests from the Google Maps API, and I'm trying to do it with Axios. Here is the first request, which is in componentWillMount() axios.get('https://maps.googleapis.com/maps/api/geocode/json?&address=' + this.props.p1) .then(response => this.setState({ p1Location: response.data })) } Here is the second request: axios.get('https://maps.googleapis.com/maps/api/geocode/json?&address=' + this.props.p2) .then(response => this.setState({ p2Location: response.data })) Then

Axios Interceptors retry original request and access original promise

断了今生、忘了曾经 提交于 2019-11-27 05:25:48
问题 I have an interceptor in place to catch 401 errors if the access token expires. If it expires it tries the refresh token to get a new access token. If any other calls are made during this time they are queued until the access token is validated. This is all working very well. However when processing the queue using Axios(originalRequest) the originally attached promises are not being called. See below for an example. Working interceptor code: Axios.interceptors.response.use( response =>