Tag: axios

发送后无法设置标题。 Nodejs /用axiosexpression

我看到这个错误,更多的是想知道如何解决这个问题。 我需要能够输出数据作为JSON对象。 无论如何要解决这个问题。 我基本上是从教程复制和粘贴,并不知道为什么我得到它在这里,除了深层请求电话可能吗? 这是错误: Error: Can't set headers after they are sent. [0] at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:344:11) [0] at ServerResponse.header (C:\Users\Amazo\Thrifa\moovr\node_modules\keystone\node_modules\express\lib\response.js:730:10) [0] at ServerResponse.send (C:\Users\Amazo\Thrifa\moovr\node_modules\keystone\node_modules\express\lib\response.js:170:12) [0] at ServerResponse.json (C:\Users\Amazo\Thrifa\moovr\node_modules\keystone\node_modules\express\lib\response.js:256:15) [0] at C:/Users/Amazo/Thrifa/moovr/src/server/API/routes/offers.js:28:21 [0] at Promise.<anonymous> (C:/Users/Amazo/Thrifa/moovr/src/server/API/controllers/store/OfferController.js:25:7) [0] at Promise.<anonymous> (C:\Users\Amazo\Thrifa\moovr\node_modules\keystone\node_modules\mongoose\node_modules\mpromise\lib\promise.js:177:8) [0] at emitOne (events.js:77:13) [0] at Promise.emit (events.js:169:7) [0] at Promise.emit (C:\Users\Amazo\Thrifa\moovr\node_modules\keystone\node_modules\mongoose\node_modules\mpromise\lib\promise.js:84:38) [0] at Promise.fulfill […]

422不返回发送消息(Node.js / Redux)

我有一个问题,我的node.js服务器正在向浏览器返回一个422消息,但浏览器只是看到了422,没有任何消息。 //Node.js if (existingUser) { return res.status(422).send({ error: 'Email is in use' }); } 我可以确认它正在那里,然后返回 //Redux method export function signupUser({ email, password }) { return function(dispatch) { return axios.post(`${ROOT_URL}/signup`, { email, password }) .then(response => { dispatch(emailWasSent(response.data.return_msg)); }) .catch(response => { dispatch(authError(response.data.error));}); } } 它会触发渔获,但回应只包含422 //Console.log of response Error: Request failed with status code 422

React defaultValue不工作axios传递dynamic数据

你好即时新在React和即时通讯尝试玩一点与反应,但inheritance人一点我不明白。 首先,获取axios数据谁返回我的数据,下面,然后我尝试把它们放入input字段,值(和只读),defaultValue更好,现在我有问题,我什么都看不到,值存在当我用萤火虫查看时,奇怪的是,当我添加一个不需要的字符input得到我想要的填充,但不是默认情况下。 非常奇怪的是,当我把所有东西放在一个数组中,并且在它上面执行一个映射函数时,我有这个值 json代码 {"firma":"hallo","strasse":"musterweg 7","plz":"01662"} js代码 import React from 'react'; import ReactDOM from 'react-dom'; import axios from 'axios'; class Testx extends React.Component { constructor(props) { super(props); this.state = { data:[] }; } componentDidMount(){ var self = this; axios.get('http://localhost/index.php') .then(function (response) { self.setState({ data: response.data}); }) .catch(function (error) { console.log(error); }); } render() { return […]

如何将id和body添加到axios.PUT请求?

我正在用REACT使用axios,并想知道如何使用它来通过我设置的后端节点/ express API来更新对象的put请求。 我需要能够通过id和body ,不知道如何这样做。 axios.put('/api/profile', id, body) .then(response => { console.log(response.data); }) .catch(err => { console.log(err); }); 我不认为这将工作,因为它需要put(url, data, {headers})

如何在节点的Axios调用中检索远程IP地址

我想在Node中进行axios调用时,获得parsing的远程URL的IP地址。 请参阅下面的***评论。 提前感谢! axios.get('http://www.example.com') .then(function (response) { // *** How can I get the resolved IP address of www.example.com here }) .catch(function (error) { console.log(error); });

在电子,如何从它的全文件名上传文件

在我的电子应用程序,我有一个button,说“上传合同”。 点击时,它从存储的合约的文件名即。 /home/users/filename.docx并获取它(不需要一个对话窗口)。 现在,我在使用axios的时候将这个文件作为多部分表单数据上传时遇到了问题。 我已经读过关于这个问题的消息,要求在axios上进行file upload,这导致了这个浏览器上的file upload请求,并且这个pull在node.js中上传 。 我已经阅读了应用程序的一些问题和意见,但似乎有困难让真正的文件正确使用axios上传。 这是我一直在做的事情。 作为浏览器上传 export function generateContract(fileUrl, customer) { const data = new FormData() const file = fs.createReadStream(fileUrl) data.append('names', customer.names) data.append('email', customer.email) data.append('contract', file) return data } //- In between generateContract & uploadFile function some function //- gets the generatedContract data & push it to uploadFile for axios […]

cURL的formsaxios或ajax是什么?

我正在创build一个任务来发送PUT请求,并在节点中使用axios上传.pot文件。 我可以跑 curl -i -u api:<api-key> -F file=@dist/file.pot https://api-link.com/v2/api 它会正常工作 我试过在节点上做这个 var fd = require('form-data'); var axios = require('axios'); var form = new FormData(); form.append('file', 'dist/file.pot'); var header = { headers: Object.assign({}, apiToken(), form.getHeaders()) }; axios.put('https://api-link.com/v2/api/', form, header) .then(function(res) { console.log(res); }) .catch(function(err) { console.log(err); }) 这不像curl命令。 apiToken()是处理curl命令的-u api:<api-key>部分的函数,它返回{'Authorization': 'Basic <api-key>'} 。 我已经检查过该function,因为我能够成功地执行获取请求。 那么在ajax或axios中相当于-F file=@dist/file.pot是什么?

如何使用axios在我的POST请求上传递唯一的属性值?

const postResponse = await axios.post(`${baseUrl}register`, { name: `Nadia`, email: 'nadia@noemail.com' } 你好! 所以我的发布请求有特定的有效负载集,但是当使用的名称已经存在时,它将进行validation。 我想知道如何在每次运行时赋予属性名称一个独特的值。 非常感谢!

将传递的属性值存储在另一个函数中使用的variables中

题.. 我想传递我在HTTP POST请求中使用的属性值,所以我可以在另一个testing中使用它。 const device = `28` + (new Date().getTime()) describe('register device', () => { test('create device registration', async () => { try { const registerDevice= await axios.post(`${baseUrl}register`, { deviceId: (`${deviceId}`), platformId: 'ios', osVersion: '11.0' }, { timeout, headers: { 'Authorization': `Bearer ${tokenGenerator.generateAuthToken({ name: 'namehere' })}` } }) expect(registerDevice.status).toBe(200) }) }) 我想从上面的POST请求传递给deviceId使用相同的值,所以我可以把它放在我的下一个POST请求的负载上。任何build议都会有帮助。 谢谢!

如何在使用axiosredirect之后获取着陆页url

如果我在maxRedirects = 5的情况下使用axios,如果我input一个将被redirect到另一个URL的URL,我如何才能从最终的login页面获取URL? 在HTTP标题中,当有200个代码时,没有用于login页面的标题字段。 例如:如果我使用 axios.get('http://stackoverflow.com/',config) .then(function(response) { console.log(response);} 它将redirect到https://stackoverflow.com 。 那么怎么才能得到最终的URL值“ https://stackoverflow.com ”? 我应该调查并重新创build完整的url吗?