1

XMLHttpRequest supports protocols other than HTTP (file and ftp). Fetch API does not seem to support it currently - is this correct and if so, is support for other protocols planned?

bastien
  • 2,940
  • 1
  • 13
  • 23
  • 2
    The Fetch API and XHR API both only support HTTPS and HTTP for cross-origin requests. It isn’t true that XHR supports making requests to ftp URLs or file URLs. I’ve updated the MDN article to remove the incorrect information it had about that. As far as file URLs, if you’re testing locally and have a HTML document/application on your local filesystem that you’ve opened in a browser, some browsers will allow you to use file URLs with XHR in that context. But once you actually put that HTML document/application up on the web and serve it from a web server, any file URLs you’ve used won’t work. – sideshowbarker Mar 13 '19 at 11:10
  • 3
    See also the answer at https://stackoverflow.com/a/15100922/441757. The gist of it is, the same-origin policy prevents accessing responses cross-origin, and the only way to relax that restriction is to use the CORS protocol, which relies on the response having certain HTTP headers. And only an HTTP or HTTPS response can include HTTP headers. So using HTTPS or HTTP as the protocol is the only way you can make a request to a server that can send back a response that’ll have the HTTP headers necessary for the CORS protocol to be used for relaxing the same-origin policy. – sideshowbarker Mar 13 '19 at 11:24
  • Thanks for the answers and links @sideshowbarker. – bastien Mar 15 '19 at 11:33

0 Answers0