https://kotlinlang.org logo
Title
a

Arjan van Wieringen

05/30/2022, 6:20 PM
Maybe I am overlooking things, but i want to make a simple request using the Ktor Client in JS to https://xkcd.com/info.0.json However, the xkcd server doesn't have CORS enabled and as such Chrome is blocking it. But I can't find how to set
mode
to
no-cors
for Ktor Client in JS.
a

Aleksei Tirman [JB]

05/30/2022, 6:26 PM
So are you making a request from a browser environment?
a

Arjan van Wieringen

05/30/2022, 7:16 PM
Yes, to a server I don't control
a

Aleksei Tirman [JB]

05/30/2022, 7:20 PM
Then you can’t do a cross origin request.
a

Arjan van Wieringen

05/30/2022, 7:23 PM
But you can, when using the browser fetch API and setting mode to no-cors.
But not using Ktor Client
However, I decided to make my life easier and found a CORS enabled version of the API: https://github.com/mrmartineau/xkcd-api
And voila, it works