Worker Request 302

I’m trying to inject some html retrieved from a 3rd party service. I can make the request using an HttpClient (c#), however I’d like to do it using Workers. The 3rd party flow is as follows:

  • HTTP POST (application/x-www-form-urlencoded) to API
  • API responds with a 302
  • Following the 302 retrieves the data

The Worker code is in an early stage:

async function handleRequest(request) {
let content = ‘consignmentNumber=123456’
let headers = {
‘Content-Type’: ‘application/x-www-form-urlencoded’
}
const init = {
method: ‘POST’,
headers: headers,
body: content,
redirect: ‘follow’,
}

let response = await fetch(‘https://abc.def.ie/?deviceType=5’, init)

response = await fetch(‘https://abc.def.ie/Home/SearchResult?deviceType=5’, request)

return response
}

However it doesn’t result in a 200. I’m assuming all headers and cookies follow the redirect?