[英]how to make post request baswith ic auth and content type x-www-form-urlencoded
I should make a post request with basic auth
and login and password in body (content-type: application/x-www-form-urlencodeed
) I have tried several approaches but it does not work 我应该在正文中使用基本
auth
以及登录名和密码发出发布请求(内容类型: application/x-www-form-urlencodeed
)我尝试了几种方法,但是它不起作用
I tried this, by specifying content-type
in a header, but it does not work 我尝试通过在标头中指定
content-type
来尝试此操作,但是它不起作用
const axios = require('axios')
let session_url = '10.50.141.75:8845/auth'
const requestBody = {
login: "node js",
password: "react js"
}
const config = {
headers: {
'Content-type': 'application/x-www-form-urlencodeed'
},
auth: {
username: 'testq',
password: 'test'
}
}
axios.post(session_url,requestBody, config).then(function(response) {
console.log('Authenticated')
}).catch(function(error) {
console.log(error)
})
I got an error 500, because of the request's body was not correct 由于请求的正文不正确,我收到了500错误
In my opinion you should try: 我认为您应该尝试:
axios.post(session_url, {
data: requestBody,
headers: {
'Accept': 'application/json',
'Content-type': 'application/json'
},
auth: {
username: 'testq',
password: 'test'
}
}).then(function(response) {
console.log('Authenticated')
}).catch(function(error) {
console.log(error)
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.