Refused to get unsafe header "Content-Length" when communicating with the server

Asked 2 years ago, Updated 2 years ago, 131 views

I am creating an Android app in the development environment of monaca.
I'm trying to get information from an external server using the following logic. Refused to get unsafe header "Content-Length"
The error returns.How can I avoid it?
You can edit the .htaccess file of the server you want to access.
Thank you for your cooperation.

function funcDbGet(){
    var url = 'https://--- omitted ---';
    var req = new XMLHttpRequest();
    req.open("GET", url, true);
    req.onreadystatechange=function(){
        if(req.readyState===XMLHttpRequest.DONE){
            if(req.status===200){
                console.log("200" + req.responseText);
            }
            else{
                console.log("err" + req.status);
                console.log(req.responseText);
            }
        }
    };
    req.send(null);
}

javascript android monaca

2022-09-30 21:33

1 Answers

It seems that it is rejected by the CORS system.
Why don't you try the FAQ?

Quoted from https://docs.monaca.io/ja/faq/environment/

I'd like to enable Cross-Origin Resource Sharing (CORRS).

You can enable CORS by adding the following headers to the Cross-Origin Resource Sharing (CORS) response:

Access-Control-Allow-Origin: *

In addition to the above, if you want to allow the app or debugger side to access an external URL, configure one of the following settings:

To configure settings on the Monaca IDE: See iOS and Android settings.
When configuring settings on a configuration file: See iOS settings and Android settings.


2022-09-30 21:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.