0

So I was having the same problem as this: No 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API

And I followed the solution, and now I get a response from the server I am trying to fetch from, which is the html page. Great! But, I have a problem. I need to request the server in order to get a session id cookie, which should be in the response header, but when I log the response headers, there are none there. This is my code:

const proxyurl = "https://cors-anywhere.herokuapp.com/";
const url = "(my url)";
function requestAuth(username, password) {
  fetch(proxyurl + url)
    .then((response) => {
      console.log(response.headers);
      return response.text();
    })
    .then((contents) => console.log(contents))
    .catch(() =>
      console.log("Can’t access " + url + " response. Blocked by browser?")
    );
}

And yes, I know this isn't a POST request, the way this website works is very weird, you have to make a get request to get the session then you can make a post to auth with the session cookie.

How can I: #1: Get the response headers from the url through the proxy and #2: send a response with some http-only cookies through the proxy?

EDIT: Here is the output for the console.log(response.headers) enter image description here

oriont
  • 684
  • 2
  • 10
  • 25
  • 1
    Are you saying that `console.log(response.headers)` logs nothing at all, or are you saying that it”s missing the Set-Cookie response header? Regardless, browsers never expose the Set-Cookie response header to frontend JavaScript. So no matter what, you’re not going to be able to do anything with the Set-Cookie response header from your frontend code. – sideshowbarker Apr 04 '20 at 17:11
  • I edited my response to show the output of the response.headers. I am thinking now, that it would be a much better idea to do this in express or something. Would that allow me to view the Set-Cookie headers? – oriont Apr 04 '20 at 17:14

0 Answers0