Get redirect with network.request

Hi!

Is there a way that I can intercept a “redirect” response from a network.request?

We have a webservice that returns a HTTP 303 with the destination URL correctly set in the “Location” header. We need that URL as a response.

Is that possible or network.request just follows redirects without any control?

Thank you

-a

I’ve never seen our network.request() API return a 300 class result code.  It seems to follow the link.  

I did it by using lua sockets:

local http = require(“socket.http”)

local ltn12 = require(“ltn12”)

local reqBody = createBody()

local headers = {}

headers[“Content-Type”] = “application/x-www-form-urlencoded”

headers[“Content-Length”] = string.len(reqBody)

local body, code, headers, status = http.request{

  url = myURL,

  method = “POST”,

  headers = headers,

  source = ltn12.source.string(reqBody),

  redirect = false

}

if( code == 303 ) then

  – success!!

else

  – fail :frowning:

end

And to don’t run in main thread, I execute inside a timer.performWithDelay with delay 1ms.

The Lua sockets method will work for http: but not https:, though it may pick up a redirect since that part of the communications isn’t encrypted.

I’ve never seen our network.request() API return a 300 class result code.  It seems to follow the link.  

I did it by using lua sockets:

local http = require(“socket.http”)

local ltn12 = require(“ltn12”)

local reqBody = createBody()

local headers = {}

headers[“Content-Type”] = “application/x-www-form-urlencoded”

headers[“Content-Length”] = string.len(reqBody)

local body, code, headers, status = http.request{

  url = myURL,

  method = “POST”,

  headers = headers,

  source = ltn12.source.string(reqBody),

  redirect = false

}

if( code == 303 ) then

  – success!!

else

  – fail :frowning:

end

And to don’t run in main thread, I execute inside a timer.performWithDelay with delay 1ms.

The Lua sockets method will work for http: but not https:, though it may pick up a redirect since that part of the communications isn’t encrypted.

Hey Felipe, I was looking at your code. Where are you doing the network request? I do not see that in your example. 

If you do not mind I would really appreciate it you could post a more complete example. Thank you I am really stuck on this!!!

local body, code, headers, status = http.request{

  url = myURL,

  method = “POST”,

  headers = headers,

  source = ltn12.source.string(reqBody),

  redirect = false

}

 That is the network request.

Hey Felipe, I was looking at your code. Where are you doing the network request? I do not see that in your example. 

If you do not mind I would really appreciate it you could post a more complete example. Thank you I am really stuck on this!!!

local body, code, headers, status = http.request{

  url = myURL,

  method = “POST”,

  headers = headers,

  source = ltn12.source.string(reqBody),

  redirect = false

}

 That is the network request.