Tag: axios

SSL证书 – 禁用axios中的validation并作出反应

我试图在使用axios的应用程序中使用API​​。 该API通过使用自签名证书的HTTPS进行工作。 到目前为止,连接时出现以下错误: net::ERR_INSECURE_RESPONSE bundle.js:65253 HTTP Failure in Axios Error: Network Error at createError (bundle.js:2188) at XMLHttpRequest.handleError (bundle.js:1717) 我尝试了以下,但没有成功: import axios from 'axios'; const https = require('https'); const agent = new https.Agent({ rejectUnauthorized: false, }); const client = axios.create({ //all axios can be used, shown in axios documentation baseURL: process.env.REACT_APP_API_URL, responseType: 'json', withCredentials: true, httpsAgent: […]

App组件刷新时丢失currentUser?

我目前正在使用React, Node.js ,passport-google-oauth20来开发一个简单的web应用程序。 出于某种原因,无论何时应用程序重新装入,我都将失去当前的用户状态。 就好像req.user只是丢失了一样。 它的工作方式是当应用程序挂载时,首先获取当前用户,并将this.state.currentUser设置为结果。 问题是页面刷新的时候。 组件重新挂载,我失去了用户。 我试图logging用户,并收到空。 希望我解释得很好…这是代码: 应用组件: import React from 'react'; import List from './List'; import ListForm from './ListForm'; import * as helpers from '../helpers'; class App extends React.Component{ state = { currentUser: '', } componentDidMount() { helpers.fetchUser() .then(data => { this.setState({ currentUser: data }); }); } onSubmit = (id, item) […]

如何使用asynchronous函数?

目前正在开发一个从客户端服务器向后端服务器发出axios请求的应用程序。 有时候应用程序更新正确,有时会滞后/不会更新,直到下一个请求。 任何想法为什么? 我的代码有什么问题吗? 我会尝试添加相关的所有内容。 该应用程序是一个购物清单,用户可以通过Google oauth简单login。 然后,他们从React State和MongoDB数据库中添加/删除项目。 每次添加/删除项目时,都会从数据库中提取列表的状态。 应用组件 import React from 'react'; import ListForm from './ListForm'; import ListItem from './ListItem'; import * as helpers from '../helpers'; class App extends React.Component{ state = { currentUser: {}, items: [] } componentDidMount() { helpers.fetchUser() .then(data => { this.setState({ currentUser: data, items: data.shoppingList }, () => […]

如何使用axios将图像(大文件)上传到服务器

我是这个社区的新手。 实际上,我正在做一个使用React的小型项目,而我的服务器使用mongodb数据库运行express和node js。 对于较小的文件,我可以正常的与服务器通信。但是当我上传一个更大的文件时,我无法发送数据到服务器。一个空的对象被发送到服务器。 而客户端其显示的错误 “No'Access-Control-Allow-Origin'标题出现在被请求的资源上,因此Origin'http:// localhost:8000 '是不允许访问的,响应的HTTP状态码是413。 我已经在互联网上search了几个小时的解决scheme,但我还没有得到任何解决scheme。 任何人都可以帮我从这个…?

axios相当于curl –upload-file

我试图用他们的公共API上传一个gif给Gfycat。 这是在命令行上使用cURL完成的: curl https://filedrop.gfycat.com –upload-file /tmp/name 我试图用axios把它转换成Node.js: axios.post("https://filedrop.gfycat.com", { data: fs.createReadStream("/tmp/name") }).then(console.log).catch(console.log); 但与消息的错误 <?xml version="1.0" encoding="UTF-8"?>\n<Error><Code>PreconditionFailed</Code><Message>At least one of the pre-conditions you specified did not hold</Message><Condition>Bucket POST must be of the enclosure-type multipart/form-data</Condition><RequestId>6DD49EB33F41DE08</RequestId><HostId>/wyrORPfBWHZk5OuLCrH9Mohwu33vOUNc6NzRSNT08Cxd8PxSEZkzZdj/awpMU6UkpWghrQ1bLY=</HostId></Error> 被打印到控制台。 我的Node.js代码如何与cURL命令不同,以及使用axios到cURL命令的等效代码是什么?

节点服务器asynchronous调用后端服务

我是Node新手,我正在写我的第一个节点服务器。 在调用后端rest服务之后,它应该通过简单的页面来获得一个简单的获取请求。 我正在使用express来pipe理请求和axios包来作出后端请求。 问题是,服务器阻塞事件循环,我有问题了解如何调用后端asynchronous。 截至目前,前端服务器一次只能pipe理一个请求! 我期望如果后端服务每次都需要10秒的时间来回答,前端服务器可以在10秒内回答两个并发请求,而不是在20秒内。 我错在哪里? 以下是前端节点代码的摘录: app.get('/', function(req, res) { //Making the call to the backend service. This should be asynchronous… axios.post(env.get("BACKEND_SERVICE"), { "user": "some kind of input"}) .then(function(response){ //do somenthing with the data returned from the backend… res.render('homepage'); }) } 这里是后端节点代码的提取: app.post('/api/getTypes', jsonParser, function (req, res) { console.log("> API request for 'api/getTypes' […]

节点(Express) – 通过api以快递方式发送pdf

我有一个API,为我在网站上的每笔付款生成发票。 另一方面,我有一个服务器来pipe理客户端。 客户要求时我需要取pdf。 我使用node / express和axios来pipe理http调用。 我设法使用以下代码从api发送pdf: function retrieveOneInvoice(req, res, next) { Order .findOne({_id: req.params.id, user: req.user.id}) .exec((err, order) => { if(err) { } else if (!order) { res.status(404).json({success: false, message: 'Order not found!'}); } else { const filename = order.invoice.path; let filepath = path.join(__dirname, '../../../invoices' ,filename); fs.readFile(filepath, function (err, data){ res.contentType("application/pdf"); res.end(data, 'binary'); }); […]

无法读取我的API或特定的API

我真的很困惑,如果你告诉我,我的代码是错误的,我已经尝试了不同的API,它的工作原理。 但在我的情况下,在react.js中有几个API无法访问。 请帮助我,并纠正。 你可以尝试这些在react.js中不起作用的API,但是总是得到脚本抓取失败或networking错误: http://pp53.azurewebsites.net/pp53service.svc/viewprovincelist https://www.getpostman.com/collections/1d8df8b0b5bf27e5009b 第一个是我的API,第二个是其他。 我已经尝试了邮差和其他编程语言和其他框架,如ASP.NET MVC的API,但它不再麻烦了。 但是当我尝试与axios react.js,获取,即使ajax该API将无法正常工作。 有没有人可以向我解释为什么? 因为如果你使用这一个https://api.myjson.com/bins/1cfkej或这个http://jsonplaceholder.typicode.com/todos没有问题。 谢谢!! 这是我的代码 import React from 'react'; import axios from 'axios'; export class viewDetailPP53 extends React.Component { constructor(props) { super(props); this.state = { count : [] }; } componentDidMount(){ var self = this; axios.get('http://pp53.azurewebsites.net/pp53service.svc/viewprovincelist') .then(function (results) { self.setState({ count: results.data }); }) .catch(function […]

如何在nodejs中的axios POST请求中传递文本/纯文本内容

我想通过身体参数如屏幕截图所示 ( 以文本/纯文本格式 ) 我在我的nodejs / express项目中使用axios。 我的reqeust格式如下所示: var config = { headers: { 'Content-Length': 0, 'Content-Type': 'text/plain' } }; const testInput = (req, res) => { axios.post('https://api.sandbox.xyz.com/v1/order/new', { firstName: 'Marlon' }, config) .then(function(response) { console.log('saved successfully') }) .catch(function(error) { console.log(error); }); }; 为此我怎样才能适当地传递身体参数?

如何访问谷歌云存储中的对象?

我试图build立一个应用程序,将访问我的谷歌云存储中的文件,而桶是私人的。 文档不清楚如何做,以便从服务器访问存储桶。 我有他们提供的JSON文件。 我打算使用nodejs公开桶上的文件,但我不知道如何授权请求到桶。 我正在使用axios。 我是否创build一个API键或使用一个键作为查询string? 一些帮助将不胜感激!