0

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,
asked Dec 28, 2021 at 1:58
5
  • I couldn't see your access token on Postman screenshot. Commented Dec 28, 2021 at 2:16
  • This is a login operation, so there is no "token" or not Commented Dec 28, 2021 at 2:19
  • 192.168.8.131:7100/auth/mock?aa=9999999 Commented Dec 28, 2021 at 2:24
  • That is working? Commented Dec 28, 2021 at 2:43
  • 1
    Yes,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" Commented Dec 28, 2021 at 3:07

3 Answers 3

0
 
 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)
answered Dec 28, 2021 at 2:41
Sign up to request clarification or add additional context in comments.

1 Comment

Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes.
0

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

answered Dec 28, 2021 at 2:54

1 Comment

Ok thanks. I found the problem, it was the express server turned on strict mode, and then I wrote an extra symbol on the url address
0

192.168.8.131:7100/auth/mock?aa=9999999

I think the url should be this

answered Dec 28, 2021 at 3:09

1 Comment

Yes, you're right

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.