Tag: axios

Axios post request.body是空的对象

我正在尝试从我的反应中发布数据。 后端 – expression。 这是后端代码: var express = require('express'); var app = express(); var bodyParser = require("body-parser"); var methodOverride = require("method-override"); var mongoose = require("mongoose"); var expressSanitizer = require("express-sanitizer"); mongoose.connect("mongodb://localhost/blog-react"); //app config app.set("view engine", "ejs"); app.use(express.static("public")); app.use(bodyParser.urlencoded({extended: true})); //must be after parser app.use(expressSanitizer()); app.use(methodOverride("_method")); //schema config var blogSchema = new mongoose.Schema({ title: String, image: String, […]

你怎么用Axios发送图像到节点js?

有没有办法发送图像(或单个图像)的数组使用axios的节点? 我使用的axios代码(我在前端使用了js): onFormSubmit(event){ event.preventDefault(); let payload = this.state; console.log("in onFormSubmit!!! with state: ", this.state, "and payload: ", payload); axios.post('/api/art', payload) .then(function(response){ console.log('saved successfully') }); 我所做的研究表明,也许有没有支持的方式发送图像文件到使用axios的节点,但这对我来说似乎很奇怪。 有没有办法?

在Node.js中使用axios发布表单数据

我正在testingPostman上的Uber API,并且能够成功发送带有表单数据的请求。 当我尝试使用Node.js和axios库翻译这个请求时,我得到一个错误。 这是我的邮差请求的样子: 我得到的回应是: { "error": "invalid_client" } 以下是我在Node.js和axios中所做的: var axios = require("axios"); const config = { headers: { 'Content-Type': 'multipart/form-data' } }; axios.post('https://login.uber.com/oauth/v2/token', { client_id: '***', client_secret: '***', grant_type: 'authorization_code', redirect_uri: 'http://localhost:8080/', code: '***' }, config) .then(function(response) { console.log(response.data) }) .catch(function(error) { console.log(error) }) 当我这样做,我得到一个400响应。 我添加了'multipart/form-data'标题,因为我填写了邮递员请求中的表单数据。 没有头我得到相同的结果。 我期望得到我从邮差得到的相同的响应,有没有在我的configurationvariables在Node.js脚本错了吗? 任何帮助,将不胜感激!

错误:getaddrinfo ENOTFOUND

我有一个简单的Node.js机器人,每秒都会向其他API发送HTTP请求。 如果返回的数据是正确的,那么我构build一个URL我的HTTP POST。 一切正常,但运行4-5小时后,我得到了这个错误 0|server | error: Error: getaddrinfo ENOTFOUND www.rest-api.com www.rest-api.com:443 0|server | at errnoException (dns.js:28:10) 0|server | at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:73:26) 有人可以向我解释为什么会发生这种情况吗? 重新启动我的服务器后,一切正常工作。 我使用axios来提出http请求。

从React(同构应用程序)进行API调用时出现“Access-Control-Allow-Origin”问题

我遇到了使用React和Express的同构JavaScript应用程序的问题。 我正在尝试使用axios.get在组件装入时发出HTTP请求 componentDidMount() { const url = 'http://ufc-data-api.ufc.com/api/v3/iphone/fighters/title_holders'; axios.get(url).then( res => { //use res to update current state }) } 我从API获取状态200 res,但我没有得到任何响应数据,并在我的控制台中得到一个错误 XMLHttpRequest cannot load http://ufc-data-api.ufc.com/api/v3/iphone/fighters/title_holders. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. 但是,如果我在我的server.js中发出请求 const url = 'http://ufc-data-api.ufc.com/api/v3/iphone/fighters/title_holders'; axios.get(url).then(res => { //console.log(res); }); 它工作正常,我得到服务器启动时的响应数据。 这是一个与实际的API问题,或者我做错了什么? 如果这是一个CORS问题,我猜在server.js中的请求也不会工作吗? […]

axios:通过代理https请求

我正在尝试使用代理服务器的axios进行https呼叫: const url = "https://walmart.com/ip/50676589" var config = { proxy: { host: proxy.ip, port: proxy.port } } axios.get(url, config) .then(result => {}) .catch(error => {console.log(error)}) 我使用的代理服务器在美国都是非常匿名的,支持HTTP和HTTPS。 我收到这个错误: {错误:写EPROTO 140736580649920:错误:140770FC:SSL例程:SSL23_GET_SERVER_HELLO:未知协议:../ deps / openssl / openssl / ssl / s23_clnt.c:794: 为了确保问题是与axios而不是代理,我试过这个: curl -x 52.8.172.72:4444 -L'https://www.walmart.com/ip/50676589' 这完全正常工作。 我如何configurationaxios以使用代理和https URL?

Node.js HTTP GET“ECONNRESET”读取时出错

我已经阅读了关于这个错误的所有关于SO和GitHub的相关问题,他们都没有解决这个问题。 当我运行下面的代码: response = await axios.get('http://localhost:8082/panda, { httpAgent: new http.Agent({ keepAlive: true, keepAliveMsecs: 10000 }) }); 我得到以下错误: { Error: socket hang up at createHangUpError (_http_client.js:345:15) at Socket.socketOnEnd (_http_client.js:437:23) at emitNone (events.js:110:20) at Socket.emit (events.js:207:7) at endReadableNT (_stream_readable.js:1059:12) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickCallback (internal/process/next_tick.js:180:9) code: 'ECONNRESET' } { Error: read ECONNRESET at _errnoException (util.js:1019:11) at TCP.onread […]

Axios(在React本地)不在本地主机调用服务器

我正在构build一个非常简单的API和反应原生应用程序。 服务器工作正常(用PostMantesting),但应用程序不调用服务器。 它会阻止axios发送邮件请求(见下文)。 我绝望了:-(放松的时间,请帮忙,如果你能帮我… 这是我的代码LogIn页面。 它派遣行动的创造者(使用REDX)给予电子邮件和密码: … const LogIn = React.createClass({ submitLogin() { // log in the server if (this.props.email !== '' && this.props.psw !== '') { if (this.props.valid === true) { this.props.dispatch(logIn(this.props.email, this.props.psw)); } else { this.props.dispatch(errorTyping()); } } }, … 电子邮件和密码被取回并发送给动作创build者: import axios from 'axios'; import { SIGNIN_URL, SIGNUP_URL } from '../api'; // […]

让Axios自动发送cookies

我正在使用Axios将客户端的请求发送到我的Express.js服务器。 我在客户端设置了一个cookie,我想从所有的Axios请求中读取这个cookie,而不用手工添加它们来请求。 这是我的客户请求示例: axios.get(`some api url`).then(response => … 我试图通过在我的Express.js服务器中使用这些属性来访问标头或cookie: req.headers req.cookies 他们都没有包含任何cookies。 我正在使用cookieparsing器中间件: app.use(cookieParser()) 如何让Axios自动发送请求中的cookies? 编辑: 我在客户端上设置cookie如下所示: import cookieClient from 'react-cookie' … let cookie = cookieClient.load('cookie-name') if(cookie === undefined){ axios.get('path/to/my/cookie/api').then(response => { if(response.status == 200){ cookieClient.save('cookie-name', response.data, {path:'/'}) } }) } … 虽然它也使用Axios,但与问题无关。 一旦cookie被设置,我只想将cookieembedded到我的所有请求中。

Axios Http客户端 – 如何构buildHttpurl与forms参数

我想创build一个postHTTP请求与一些表单参数将被设置。 我正在使用节点服务器的axios。 我已经有一个Java代码实现构造一个url,如下所示: JAVA代码: HttpPost post = new HttpPost(UriBuilder.fromUri (getProperty("authServerUrl")) .path(TOKEN_ACCESS_PATH).build(getProperty("realm"))); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new NameValuePair("username",getProperty ("username"))); formParams.add(new NameValuePair("password",getProperty ("password"))); formParams.add(new NameValuePair("client_id, "user-client")); 我正在尝试在axios中做同样的事情。 AXIOS实施: axios.post(authServerUrl +token_access_path, { username: 'abcd', //gave the values directly for testing password: '1235!', client_id: 'user-client' }).then(function(response) { console.log(response); //no output rendered } 在提交请求中设置这些表单参数的方法是否正确?