How to fix the error when working with fetch construct?

  • 0
    Good afternoon. I make a request to the server as follows
    try {
      let response = await fetch("https://192.168.12.4:8081/trsite", {
       method: 'POST', // или 'PUT'
        body: jsonToMap, // данные могут быть 'строкой' или {объектом}
        headers: {
         'Content-Security-Policy': 'connect-src https://mail.ru/',
         'Content-Type': 'application/json;charset=utf-8'
        }
     });
      let json = await response.json();
      convertJsonToMap(json)
      console.log('Успех:', JSON.stringify(json));
        
    } catch (error) {
      //console.error('Ошибка:', error);
    }

    Then the answer comes and I work partially with the answer and the site on which I ran the code. I didn't post the whole code, it seems like a problem in this construction.

    On some, the page works fine. But others get a whole bunch of mistakes. Here's an example
    VM3922:10 Refused to connect to 'https://192.168.12.4:8081/trsite' because it violates the following Content Security Policy directive: "connect-src *.adlooxtracking.com *.adsafeprotected.com *.criteo.com *.doubleverify.com *.imgsmail.ru *.mail.ru *.moatads.com *.mradx.net *.serving-sys.com an.yandex.ru cdn.consentmanager.mgr.consensu.org consentmanager.mgr.consensu.org jstracer.yandex.ru mail.ru mc.yandex.by mc.yandex.fr mc.yandex.kz mc.yandex.md mc.yandex.ru mc.yandex.ua mc.yandex.uz ok.ru strm.yandex.ru yandex.ru yandex.st yastat.net yastatic.net".
    
    (anonymous) @ VM3922:10
    VM3922:10 [Report Only] Refused to connect to 'https://192.168.12.4:8081/trsite' because it violates the following Content Security Policy directive: "connect-src *.adlooxtracking.com *.adsafeprotected.com *.criteo.com *.doubleverify.com *.imgsmail.ru *.mail.ru *.moatads.com *.mradx.net *.serving-sys.com an.yandex.ru cdn.consentmanager.mgr.consensu.org consentmanager.mgr.consensu.org jstracer.yandex.ru mail.ru mc.yandex.by mc.yandex.fr mc.yandex.kz mc.yandex.md mc.yandex.ru mc.yandex.ua mc.yandex.uz ok.ru strm.yandex.ru yandex.ru yandex.st yastat.net yastatic.net".
    
    (anonymous) @ VM3922:10
    VM3922:10 Refused to connect to 'https://192.168.12.4:8081/trsite' because it violates the document's Content Security Policy


    As far as I understand, it lacks the written Content Security Policy in the header. How to write correctly to get rid of these errors?
    JavaScript Xander Hanson, Oct 20, 2019

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!