Amareis / another-rest-client

Simple pure TypeScript REST API client that makes your code lesser and more beautiful than without it.
MIT License
174 stars 17 forks source link

Not getting expected headers in XmlHttpRequest during a response #10

Closed mmacphail closed 6 years ago

mmacphail commented 6 years ago

Hello,

I use the following snippet:

    const api = new RestClient("http://localhost:8080/mgag/api");
    api.res("users");
    api.users.post(data).then(function (evt) {
        console.log(evt);
    }, function (other) {
        alert("Unable to subscribe");
        console.log(other);
        console.log(other.getAllResponseHeaders());
    });

Unfortunately, the other parameter doesn't contain any useful headers even if the server sends them.

What I'm getting in Mozzilla Developper Console: image

image

I want to grab the "Cause" header here.

Please note that I use CORS.

Amareis commented 6 years ago

Why you have "http://localhost:8080/app/api" URL in code, but "http://localhost:8080/mgag/app/api" URL in dev tools? Notice /mgag/ part.

Amareis commented 6 years ago

Also, look here: https://stackoverflow.com/questions/8945587/xmlhttprequest-getallresponseheaders-not-returning-all-the-headers

mmacphail commented 6 years ago

The url is http://localhost:8080/mgag/api ; I misstype app in my question let me edit this for posterity.

Indeed, I had to expose my CORS headers and that was th problem. Thanks 👍 !

Amareis commented 6 years ago

If you want to thanks me, just star the repo ;)