Home > database >  Unable to receive parameters in GET request, openstf-nodejs
Unable to receive parameters in GET request, openstf-nodejs

Time:12-28

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-27T12:10:17.445557755Z *********mock.js----app.get(/auth/mock)***token is null*****
....
2021-12-27T12:10:17.498524013Z   baseUrl: '',
2021-12-27T12:10:17.498540313Z   originalUrl: '/auth/mock/',
2021-12-27T12:10:17.498556313Z   _parsedUrl: 
2021-12-27T12:10:17.498571913Z    Url {
2021-12-27T12:10:17.498587413Z      protocol: null,
2021-12-27T12:10:17.498602913Z      slashes: null,
2021-12-27T12:10:17.498618513Z      auth: null,
2021-12-27T12:10:17.498634113Z      host: null,
2021-12-27T12:10:17.498649813Z      port: null,
2021-12-27T12:10:17.498665413Z      hostname: null,
2021-12-27T12:10:17.498681114Z      hash: null,
2021-12-27T12:10:17.498699114Z      search: null,
2021-12-27T12:10:17.498714914Z      query: null,
2021-12-27T12:10:17.498825715Z      pathname: '/auth/mock/',
2021-12-27T12:10:17.498845515Z      path: '/auth/mock/',
2021-12-27T12:10:17.498862115Z      href: '/auth/mock/',
2021-12-27T12:10:17.498877915Z      _raw: '/auth/mock/' },
2021-12-27T12:10:17.498893515Z   params: {},
2021-12-27T12:10:17.498909115Z   query: {},
....
2021-12-27T12:10:17.477325069Z   headers: 
2021-12-27T12:10:17.477340870Z    { host: '192.168.8.131:7100',
2021-12-27T12: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-27T12:10:17.477372470Z      'upgrade-insecure-requests': '1',
2021-12-27T12:10:17.477388270Z      referer: 'http://192.168.8.131:7100//auth/mock?aa=9999999',
2021-12-27T12:10:17.477404270Z      cookie: 'ssid=eyJqd3QiOnsiZW1haWwiOiJjaGVucnVpeGlANDM5OWluYy5jb20iLCJuYW1lIjoiY2hlbnJ1aXhpIn0sImNzcmZTZWNyZXQiOiJsXzB6VEJ5VUdSMUZpM21ZeVVPdnVVMzYifQ==; ssid.sig=NNFfR9rcuBXMOvIOoaSokTwe6Uw; XSRF-TOKEN=CnI0l5Xy-P4fP1UxAcRgWARJJ-I59bY5YJjo',
2021-12-27T12:10:17.477420370Z      connection: 'close',
2021-12-27T12:10:17.477436170Z      'accept-language': 'zh-CN',
2021-12-27T12:10:17.477451670Z      'accept-encoding': 'gzip, deflate, br',
2021-12-27T12:10:17.477467370Z      accept: '*/*' },
2021-12-27T12:10:17.477482870Z   rawHeaders: 
2021-12-27T12:10:17.477498471Z    [ 'host',
2021-12-27T12:10:17.477514071Z      '192.168.8.131:7100',
2021-12-27T12:10:17.477529971Z      'user-agent',
2021-12-27T12: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-27T12:10:17.477562571Z      'upgrade-insecure-requests',
2021-12-27T12:10:17.477578371Z      '1',
2021-12-27T12:10:17.477594271Z      'referer',
2021-12-27T12:10:17.477610271Z      'http://192.168.8.131:7100//auth/mock?aa=9999999',
2021-12-27T12:10:17.477632572Z      'cookie',
2021-12-27T12:10:17.477649172Z      'ssid=eyJqd3QiOnsiZW1haWwiOiJjaGVucnVpeGlANDM5OWluYy5jb20iLCJuYW1lIjoiY2hlbnJ1aXhpIn0sImNzcmZTZWNyZXQiOiJsXzB6VEJ5VUdSMUZpM21ZeVVPdnVVMzYifQ==; ssid.sig=NNFfR9rcuBXMOvIOoaSokTwe6Uw; XSRF-TOKEN=CnI0l5Xy-P4fP1UxAcRgWARJJ-I59bY5YJjo',
2021-12-27T12:10:17.490127156Z      'connection',
2021-12-27T12:10:17.490145056Z      'close',
2021-12-27T12:10:17.490161156Z      'accept-language',
2021-12-27T12:10:17.490176956Z      'zh-CN',
2021-12-27T12:10:17.490192656Z      'accept-encoding',
2021-12-27T12:10:17.490208256Z      'gzip, deflate, br',
2021-12-27T12:10:17.490223957Z      'accept',
2021-12-27T12:10:17.490239757Z      '*/*' ],
2021-12-27T12:10:17.490255557Z   trailers: {},
2021-12-27T12:10:17.490271257Z   rawTrailers: [],
2021-12-27T12:10:17.490287057Z   upgrade: false,
2021-12-27T12:10:17.490303457Z   url: '/auth/mock/',
2021-12-27T12:10:17.490319457Z   method: 'GET',
2021-12-27T12:10:17.490335257Z   statusCode: null,

CodePudding user response:

  
  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)

CodePudding user response:

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

CodePudding user response:

192.168.8.131:7100/auth/mock?aa=9999999

I think the url should be this

  • Related