Friday, November 25, 2022
HomeGame DevelopmentHtpp put up and get in cocos creator - Cocos Creator

Htpp put up and get in cocos creator – Cocos Creator


hey guys dev,
I’ve an issue with my api, I needed to combine my api with an http script and I made request for get and ship for put up
However the issue is on the degree of the put up which makes an error once I could make the process of registration of a participant, I obtain an error once I introduce a phone quantity in my ship I clear up an error

const url_server="https://take a look at.fapfap.jambo-games.com"
import md5 from "md5";
const now = Date.now()
let hash



var HTTP = {
    Request : operate(path,information,handler,port=""){
            var xhr = cc.loader.getXMLHttpRequest();
		var url = url_server+port;
            xhr.timeout = 10000;
            var str = "?";
            for(var ok in information){
                if(str != "?"){
                    str += "&";
                }
                str += ok + "=" + information[k];
            }
           
            var requestURL = url + path + encodeURI(str);
            console.log("RequestURL:" + requestURL);
            xhr.open("GET",requestURL, true);
            if (cc.sys.isNative){
                xhr.setRequestHeader("Settle for-Encoding","gzip,deflate","textual content/html;charset=UTF-8");
            }
            xhr.setRequestHeader('Content material-Sort', 'utility/x-www-form-urlencoded; charset=UTF-8')  
            xhr.onreadystatechange = operate() {
                if(xhr.readyState === 4 && (xhr.standing >= 200 && xhr.standing < 300)){
                    strive {
                        var ret = xhr.responseText;
                        if(handler !== null){
                            handler(ret);
                        }                        /* code */
                    } catch (e) {
                        console.log("err:" + e);
                        handler(null);
                    }
                }
            };
            
            xhr.ship();
            return xhr;
    },
    ship : operate(path,information,handler,port=""){
        var xhr = cc.loader.getXMLHttpRequest();
		var url = url_server+port;
        xhr.timeout = 2000;
        var str = "";
        for(var ok in information){
            if(str != "?"){
                str += "&";
            }
            str += ok + "=" + information[k];
        }
        var extraUrl = url;
        var requestURL = extraUrl +path
        xhr.open("put up",requestURL, true);
        if (cc.sys.isNative){
            xhr.setRequestHeader("Settle for-Encoding","gzip,deflate","textual content/html;charset=UTF-8");
        }
        xhr.setRequestHeader('Content material-Sort', 'utility/x-www-form-urlencoded; charset=UTF-8')

        cc.loader.loadRes("env", (err, env) =>{
            hash = md5(now + env.json.ENC_KEY)
            xhr.setRequestHeader('Settle for', 'utility/json')
            xhr.setRequestHeader('Authorization-Timestamp', now)
            xhr.setRequestHeader('Authorization-Hash', hash) 
            console.log('xhr', xhr)
            xhr.onreadystatechange = operate() {
                if(xhr.readyState === 4 && (xhr.standing >= 200 && xhr.standing < 300)){
                    strive {
                        var ret = xhr.responseText;
                        if(handler !== null){
                            handler(ret);    
                        }  
                    } catch (e) { 
                        console.log("err:" + e);
                        handler(null);
                    }
                }
            }; 
            xhr.ship(str);
            return xhr;
          })
    },   
};

module.exports = HTTP

fichier http
fichier signUp

const HTTP = require('../../Http');

cc.Class({
    extends: cc.Element,

    properties: {
        phone_number: cc.EditBox
    },

    // LIFE-CYCLE CALLBACKS:

    createPlayer () {
        console.log('cellphone', this.phone_number)
       const information = {
            country_code: "CM",
           phone_number: "+237" + "695715681" ,
        }
        var onCreate = operate(res){
            console.log('resp', res)
            cc.director.loadScene("checkNumber");
        }
        console.log('information', information)

     HTTP.ship('/auth/register-or-login', information, onCreate)
    
    },

error en console

I need to know if there’s a chance that we can’t register a participant along with his quantity? Or solely with username and password?

Thanks prematurely to your solutions

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments