App.request with get method gets error or is it a BUG?

I do not know if this is a bug but it looks like, it only happens when using app.request with GET method… if using POST method there is no error at all…

My request using GET method

            app.request({
                headers: {
                    'Content-Type': ["application/json", "text/plain"],
                    'Accept': 'application/json',
                    'Accept-Encoding': 'gzip;q=1.0, compress;q=0.5',
                    'authority': 'testeapp.com'
                },
                url: ' https://myurl',
                timeout: 0,
                method: 'GET',
                data: {
                    "customer": "123212"
                },
                beforeSend: function() {
                    console.log('beforeSend');
                },
                complete: function() {
                    console.log('complete');
                },
                success: function(results) {
                    console.log('success');
                    console.log(results);

                    app.data.myResults = results;

                    setTimeout(function() {

                        app.preloader.hide();

                        resolve({
                            component: GotoPage
                        }, {
                            context: {}
                        });

                    }, 500);

                },
                error: function(xhr, textStatus, errorThrown) {
                    app.preloader.hide();

                    console.log(JSON.stringify(xhr));
                    app.dialog.alert('Error: ' + textStatus + errorThrown);
                }
            });

I have test my GET request with postman and works perfectly but not in framework7
the error I receive when using GET method:

Error:

{"_context":{"delegate":{},"requestHeaders":{"content-type":"application/json,text/plain","accept":"application/json","accept-encoding":"gzip;q=1.0, compress;q=0.5","authority":"testeapp.com","x-requested-with":"XMLHttpRequest"},"responseHeaders":{},"listeners":{},"readyState":4,"responseType":"text","withCredentials":false,"upload":{"_context":{"listeners":{}}},"status":0,"method":"GET","url":" https://myurl?customer=123212","async":true,"user":"","password":"","response":"","responseText":"","responseURL":"","statusText":""},"requestUrl":" https://myurl?customer= 123212","requestParameters":{"url":" https://myurl?customer= 123212","method":"GET","data":{"customer":"123212"},"async":true,"cache":true,"user":"","password":"","headers":{"Content-Type":["application/json","text/plain"],"Accept":"application/json","Accept-Encoding":"gzip;q=1.0, compress;q=0.5","authority":"apptest.com"},"xhrFields":{},"statusCode":{},"processData":true,"dataType":"text","contentType":"application/x-www-form-urlencoded","timeout":0,"crossDomain":false}}

Any ideas where this error comes from and how to fix GET methods when using app.request?

if I use XMLHttpRequest() it works but with app.request GET method it gives me that error above all the time!

thanks for any advice or tips!

I believe it is not a valid contentType header

'Content-Type': ["application/json", "text/plain"],

I have tested also like this and have the same error:

                headers: {
                    'Content-Type': "application/json",
                    'Accept': 'application/json',
                    'Accept-Encoding': 'gzip;q=1.0, compress;q=0.5',
                    'authority': 'apptest.com'
                },

the curious thing it is that using it with XMLHttpRequest it works

            var xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function() {
                if (this.readyState === 4) {
...
                }
            });

            xhr.open("GET", "https://myurl");
            xhr.setRequestHeader("Content-Type", "application/json");
            xhr.setRequestHeader("Accept", "application/json");
            xhr.setRequestHeader("Accept-Encoding", "gzip;q=1.0, compress;q=0.5");
            xhr.setRequestHeader("authority", "appkoala.com");
            xhr.setRequestHeader("Content-Type", "text/plain");

            xhr.send(data);

any ideas why not working with app.request with GET method?

This example works correctly in my app, I hope it helps…

    myapp.request( {
        url: URL_CALL,
        method: 'GET',
        contentType: 'application/json',
        headers: {
            'Authorization': 'Bearer' + myapp.data.token
        },
        beforeSend: function () {
            myapp.preloader.show();
        },
        data: { /*your data*/ },
        success: function ( data ) {
            console.log( data );
        },
        error: function ( xhr ) {
            console.log( xhr );
        },
        complete: function () {
            myapp.preloader.hide();
        },
        timeout: 3000
    } );
2 Likes

I will try this to see if it works with my get request this way, but it is failing all the time using app.request but not with XMLHttpRequest, very strange!

thanks for the tips I let you know if worked and found the issue somewhere!