where is the api docs for nodebb?
-
Not to be picky, but
request
is not a Promise.async
is doing nothing. -
now the code below with axios is success.
const axiosCookieJarSupport = require('axios-cookiejar-support').default; const tough = require('tough-cookie'); axiosCookieJarSupport(axios); async function authNodeBB(name,pass) { let cookieJar = new tough.CookieJar(); let instance = await axios.create({ jar:cookieJar, withCredentials: true, httpsAgent: new https.Agent({ rejectUnauthorized: false, requestCert: true, keepAlive: true}) }); let res = await instance.get('https://172.16.220.133/api/config'); console.log(res.data.csrf_token); instance.defaults.headers['x-csrf-token'] = res.data.csrf_token; res = await instance.post('https://172.16.220.133/login',{username:name,password:pass}); console.log(res.statusCode); console.log(res); }
-
the code with promised request is success
async function authBB(name,pass) { let jar = requestPromise.jar(); let res = await requestPromise({ url: 'https://172.16.220.133/api/config', json: true, jar: jar, rejectUnauthorized: false, requestCert: true, agent: false, }); console.log(res.csrf_token); res = await requestPromise.post('https://172.16.220.133/login', { form: { username: name, password: pass, }, json: true, jar: jar, rejectUnauthorized: false, requestCert: true, agent: false, headers: { 'x-csrf-token': res.csrf_token, }, // resolveWithFullResponse: true }); console.log(res.header.user); console.log(res); console.log(res.statusCode); }
-
the code with python is success
#coding=utf-8 import requests client = requests.session() csrf = client.get(url='https://172.16.220.133/api/config', verify=False).json()["csrf_token"] print csrf r = client.post(url='https://172.16.220.133/login', verify=False, data={'username':'creatxr', 'password':'creatxr'}, headers={'x-csrf-token': csrf}) print r.content
-
Copyright © 2024 NodeBB | Contributors