I ran into a strange problem: in a request sent with postman, nodejs cannot receive the parameters.
Please help me, this problem has been bothering me for several days, thank you.
The following file comes from the openstf project: https://github.com/openstf/stf/blob/master/lib/units/auth/mock.js
mock.js :
// I am create a new reqeuest handler
app.get('/auth/mock/', function(req, res) {
var token = req.query.access_token
if(!token) {
console.log('*********mock.js----app.get(/auth/mock)***token is null*****')
console.dir(req)
res.redirect('a.com')
}else{
console.log('*********mock.js----app.get(/auth/mock)**')
res.status(200)
.json({
success: true
, redirect: urlutil.addParams(options.appUrl, {
jwt: token
})
})
}
})
postman: enter image description here
console:
2021年12月27日T12:10:17.445557755Z *********mock.js----app.get(/auth/mock)***token is null*****
....
2021年12月27日T12:10:17.498524013Z baseUrl: '',
2021年12月27日T12:10:17.498540313Z originalUrl: '/auth/mock/',
2021年12月27日T12:10:17.498556313Z _parsedUrl:
2021年12月27日T12:10:17.498571913Z Url {
2021年12月27日T12:10:17.498587413Z protocol: null,
2021年12月27日T12:10:17.498602913Z slashes: null,
2021年12月27日T12:10:17.498618513Z auth: null,
2021年12月27日T12:10:17.498634113Z host: null,
2021年12月27日T12:10:17.498649813Z port: null,
2021年12月27日T12:10:17.498665413Z hostname: null,
2021年12月27日T12:10:17.498681114Z hash: null,
2021年12月27日T12:10:17.498699114Z search: null,
2021年12月27日T12:10:17.498714914Z query: null,
2021年12月27日T12:10:17.498825715Z pathname: '/auth/mock/',
2021年12月27日T12:10:17.498845515Z path: '/auth/mock/',
2021年12月27日T12:10:17.498862115Z href: '/auth/mock/',
2021年12月27日T12:10:17.498877915Z _raw: '/auth/mock/' },
2021年12月27日T12:10:17.498893515Z params: {},
2021年12月27日T12:10:17.498909115Z query: {},
....
2021年12月27日T12:10:17.477325069Z headers:
2021年12月27日T12:10:17.477340870Z { host: '192.168.8.131:7100',
2021年12月27日T12:10:17.477356470Z 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36',
2021年12月27日T12:10:17.477372470Z 'upgrade-insecure-requests': '1',
2021年12月27日T12:10:17.477388270Z referer: 'http://192.168.8.131:7100//auth/mock?aa=9999999',
2021年12月27日T12:10:17.477404270Z cookie: 'ssid=eyJqd3QiOnsiZW1haWwiOiJjaGVucnVpeGlANDM5OWluYy5jb20iLCJuYW1lIjoiY2hlbnJ1aXhpIn0sImNzcmZTZWNyZXQiOiJsXzB6VEJ5VUdSMUZpM21ZeVVPdnVVMzYifQ==; ssid.sig=NNFfR9rcuBXMOvIOoaSokTwe6Uw; XSRF-TOKEN=CnI0l5Xy-P4fP1UxAcRgWARJJ-I59bY5YJjo',
2021年12月27日T12:10:17.477420370Z connection: 'close',
2021年12月27日T12:10:17.477436170Z 'accept-language': 'zh-CN',
2021年12月27日T12:10:17.477451670Z 'accept-encoding': 'gzip, deflate, br',
2021年12月27日T12:10:17.477467370Z accept: '*/*' },
2021年12月27日T12:10:17.477482870Z rawHeaders:
2021年12月27日T12:10:17.477498471Z [ 'host',
2021年12月27日T12:10:17.477514071Z '192.168.8.131:7100',
2021年12月27日T12:10:17.477529971Z 'user-agent',
2021年12月27日T12:10:17.477546371Z 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36',
2021年12月27日T12:10:17.477562571Z 'upgrade-insecure-requests',
2021年12月27日T12:10:17.477578371Z '1',
2021年12月27日T12:10:17.477594271Z 'referer',
2021年12月27日T12:10:17.477610271Z 'http://192.168.8.131:7100//auth/mock?aa=9999999',
2021年12月27日T12:10:17.477632572Z 'cookie',
2021年12月27日T12:10:17.477649172Z 'ssid=eyJqd3QiOnsiZW1haWwiOiJjaGVucnVpeGlANDM5OWluYy5jb20iLCJuYW1lIjoiY2hlbnJ1aXhpIn0sImNzcmZTZWNyZXQiOiJsXzB6VEJ5VUdSMUZpM21ZeVVPdnVVMzYifQ==; ssid.sig=NNFfR9rcuBXMOvIOoaSokTwe6Uw; XSRF-TOKEN=CnI0l5Xy-P4fP1UxAcRgWARJJ-I59bY5YJjo',
2021年12月27日T12:10:17.490127156Z 'connection',
2021年12月27日T12:10:17.490145056Z 'close',
2021年12月27日T12:10:17.490161156Z 'accept-language',
2021年12月27日T12:10:17.490176956Z 'zh-CN',
2021年12月27日T12:10:17.490192656Z 'accept-encoding',
2021年12月27日T12:10:17.490208256Z 'gzip, deflate, br',
2021年12月27日T12:10:17.490223957Z 'accept',
2021年12月27日T12:10:17.490239757Z '*/*' ],
2021年12月27日T12:10:17.490255557Z trailers: {},
2021年12月27日T12:10:17.490271257Z rawTrailers: [],
2021年12月27日T12:10:17.490287057Z upgrade: false,
2021年12月27日T12:10:17.490303457Z url: '/auth/mock/',
2021年12月27日T12:10:17.490319457Z method: 'GET',
2021年12月27日T12:10:17.490335257Z statusCode: null,
-
I couldn't see your access token on Postman screenshot.Wang YinXing– Wang YinXing2021年12月28日 02:16:41 +00:00Commented Dec 28, 2021 at 2:16
-
This is a login operation, so there is no "token" or notxman– xman2021年12月28日 02:19:10 +00:00Commented Dec 28, 2021 at 2:19
-
192.168.8.131:7100/auth/mock?aa=9999999Wang YinXing– Wang YinXing2021年12月28日 02:24:07 +00:00Commented Dec 28, 2021 at 2:24
-
That is working?Wang YinXing– Wang YinXing2021年12月28日 02:43:23 +00:00Commented Dec 28, 2021 at 2:43
-
1Yes,it works. I changed the url address from "192.168.8.131:7100//auth/mock/?bbbb=666666" to "192.168.8.131:7100/auth/mock/?bbbb=666666"xman– xman2021年12月28日 03:07:58 +00:00Commented Dec 28, 2021 at 3:07
3 Answers 3
var app = express()
var server = Promise.promisifyAll(http.createServer(app))
//Problems caused by strict mode
app.set('strict routing', true)
app.set('case sensitive routing', true)
1 Comment
You don't have any URL param named access_token. you named it aa.
Change your URL to be like this: http://192.168.8.131:7100/auth/mock?access_token=9999999
Then when you log req.query.access_token you will have the value of 9999999
1 Comment
192.168.8.131:7100/auth/mock?aa=9999999
I think the url should be this