使用axios发出x-www-form-urlencoded请求

时间:2019-03-20 09:15:35

标签: javascript node.js

const { user } = require('./config');
const axios = require('axios');

const Querystring = require('querystring');

let body = Querystring['stringify']({
    email: 'MY EMAIL@email.com',
    password: 'pass'
})

const config = {
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
}

axios['post']('https://minecraftservers.org/login', body, config)
['then'](response => console.log(response))

我正在尝试通过网站登录 它没有API 标头正确 如果您在徘徊我如何知道这一点,我会使用chrome开发工具 像逆向工程师

content-type: application/x-www-form-urlencoded

这是我尝试登录该网站时使用的标头

这是我通过网站而不是代码登录时得到的内容,它在那里工作。 image

3 个答案:

答案 0 :(得分:3)

您可以使用heading

URLSearchParams

它避免了添加另一个库。

答案 1 :(得分:0)

尝试

# Packages -------------------------
library(ggplot2)

# Data -----------------------------
data <- data.frame(
  regime = sample(1:5, size = 100, replace = TRUE),
  rank1 = rnorm(n = 100, mean = 75, sd = 25)
)

# boxplot ---------------------------
  ggplot(data, aes(x = factor(regime), y = rank1)) +
  geom_boxplot() +
  labs(x = "Regime", y = "Rank")

答案 2 :(得分:0)

我猜想systax是您的问题。除了语法,您还有其他困难吗?

const { user } = require('./config');
const axios = require('axios');

const Querystring = require('querystring');

let body = Querystring['stringify']({
    email: 'MY EMAIL@email.com',
    password: 'pass'
})

const config = {
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
}

axios.post('https://minecraftservers.org/login', body, config)
.then(response => console.log(response))