无法使用axios在Electron中发出帖子请求(仅获取请求)

时间:2019-07-11 08:18:23

标签: javascript http https electron axios

我正在使用Electron和Axios构建一个简单的应用程序来发出http请求。但是每次我尝试向服务器发出发布请求时,都会发出一个get请求,正如我在Chrome Devtools中看到的那样。我不明白这里发生了什么。

在服务器端,我有一个Laravel后端应用程序,仅接受POST请求。

enter image description here

index.html

<html>
    <body>
        <script src="axios.min.js"></script>
        <script>
            axios.post('https://www.example.com/api/users/', {
                firstName: 'Fred',
                lastName: 'Flintstone'
            })
        </script>
    </body>
</html>

main.js

const { app, BrowserWindow } = require('electron')

let win

function createWindow () {
  win = new BrowserWindow({
    width: 530,
    height: 520,
    webPreferences: {
        nodeIntegration: true
    },
  })

  win.loadFile('index.html')
  win.setAlwaysOnTop(true)

  win.on('closed', () => {
    win = null
  })
}

app.on('ready', createWindow)

app.on('window-all-closed', () => {
    app.quit()
})

1 个答案:

答案 0 :(得分:0)

您缺少标题

Application / json

相关问题