hey guys dev,
I have a problem with my api, I had to integrate my api with an http script and I made request for get and send for post
But the problem is at the level of the post which makes an error when I can make the procedure of registration of a player, I receive an error when I introduce a telephone number in my send I solve an error
const url_server = 'https://test.fapfap.jambo-games.com'
import md5 from "md5";
const now = Date.now()
let hash
var HTTP = {
Request : function(path,data,handler,port = ''){
var xhr = cc.loader.getXMLHttpRequest();
var url = url_server+port;
xhr.timeout = 10000;
var str = "?";
for(var k in data){
if(str != "?"){
str += "&";
}
str += k + "=" + data[k];
}
var requestURL = url + path + encodeURI(str);
console.log("RequestURL:" + requestURL);
xhr.open("GET",requestURL, true);
if (cc.sys.isNative){
xhr.setRequestHeader("Accept-Encoding","gzip,deflate","text/html;charset=UTF-8");
}
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
xhr.onreadystatechange = function() {
if(xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)){
try {
var ret = xhr.responseText;
if(handler !== null){
handler(ret);
} /* code */
} catch (e) {
console.log("err:" + e);
handler(null);
}
}
};
xhr.send();
return xhr;
},
send : function(path,data,handler,port=''){
var xhr = cc.loader.getXMLHttpRequest();
var url = url_server+port;
xhr.timeout = 2000;
var str = "";
for(var k in data){
if(str != "?"){
str += "&";
}
str += k + "=" + data[k];
}
var extraUrl = url;
var requestURL = extraUrl +path
xhr.open("post",requestURL, true);
if (cc.sys.isNative){
xhr.setRequestHeader("Accept-Encoding","gzip,deflate","text/html;charset=UTF-8");
}
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
cc.loader.loadRes("env", (err, env) =>{
hash = md5(now + env.json.ENC_KEY)
xhr.setRequestHeader('Accept', 'application/json')
xhr.setRequestHeader('Authorization-Timestamp', now)
xhr.setRequestHeader('Authorization-Hash', hash)
console.log('xhr', xhr)
xhr.onreadystatechange = function() {
if(xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)){
try {
var ret = xhr.responseText;
if(handler !== null){
handler(ret);
}
} catch (e) {
console.log("err:" + e);
handler(null);
}
}
};
xhr.send(str);
return xhr;
})
},
};
module.exports = HTTP
fichier http
fichier signUp
const HTTP = require('../../Http');
cc.Class({
extends: cc.Component,
properties: {
phone_number: cc.EditBox
},
// LIFE-CYCLE CALLBACKS:
createPlayer () {
console.log('phone', this.phone_number)
const data = {
country_code: "CM",
phone_number: "+237" + "695715681" ,
}
var onCreate = function(res){
console.log('resp', res)
cc.director.loadScene("checkNumber");
}
console.log('data', data)
HTTP.send('/auth/register-or-login', data, onCreate)
},
error en console
I want to know if there is a possibility that we cannot register a player with his number? Or only with username and password?
Thank you in advance for your answers