superagent icon indicating copy to clipboard operation
superagent copied to clipboard

How can I capture 302?

Open zystudios opened this issue 1 year ago • 2 comments

I request an API, this API will return 302, and automatically jump to another API, and then return data, but I see status code has been 200, I need to capture 302 to do some operations, what should I do?

thanks

zystudios avatar May 24 '24 10:05 zystudios

You can use the following code:

http
  .get('http://example.com/')
  // following redirects
  .redirects(0)
  // error handling
  .ok(res => res.status >= 200 && res.status < 400)
  .then(res => {
    console.log(res.status)
    console.log(res.headers['location'])
  })

Reference documentation: Following Redirects: SuperAgent Documentation Error Handling: SuperAgent Documentation

woaer avatar May 27 '24 09:05 woaer

You can use the following code:

http
  .get('http://example.com/')
  // following redirects
  .redirects(0)
  // error handling
  .ok(res => res.status >= 200 && res.status < 400)
  .then(res => {
    console.log(res.status)
    console.log(res.headers['location'])
  })

Reference documentation: Following Redirects: SuperAgent Documentation Error Handling: SuperAgent Documentation

thx, I'll try later

zystudios avatar May 27 '24 15:05 zystudios