Beispiel #1
0
    private static IEnumerator SendCorrectPictures(IEnumerable <int> selected, IEnumerable <int> notSelected)
    {
        WWWForm form = new WWWForm();

        form.AddField("collection", Collection);
        form.AddField("device_id", /*DeviceId*/ 1 /*throws error without 1*/);
        form.AddField("answer_time", 15523);
        foreach (var number in selected)
        {
            form.AddField("selected_phrases[]", number);
        }

        foreach (var number in notSelected)
        {
            form.AddField("not_selected_phrases[]", number);
        }

        Debug.Log(form.ToString());

        using (UnityWebRequest www = UnityWebRequest.Post(SendManyAnswersURL, form)) {
            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                Debug.Log(www.error);
            }
            else
            {
                Debug.Log(www.downloadHandler.text);
            }
        }
    }
Beispiel #2
0
    //Sending Data to DB
    IEnumerator Upload()
    {
        Debug.Log("Sending data request");
        WWWForm form = new WWWForm();

        //form.AddField("Content-Type", "application/json");
        //form.AddField("data", "{\"Username\":\"c\",\"Email\":\"c\",\"Password\":\"c\"}");*/
        form.AddField("Username", Username);
        form.AddField("Email", Email);
        form.AddField("Password", Password);
        //form.AddField("ConfirmPassword", ConfirmPassword);
        //ScoresWebsite
        UnityWebRequest www = UnityWebRequest.Post("http://localhost:64537/Player/Register", form);

        //New Website
        //UnityWebRequest www = UnityWebRequest.Post("http:http://localhost:57724/Account/Register", form);

        www.chunkedTransfer = false;
        Debug.Log(Username);
        yield return(www.Send());

        Debug.Log(form.ToString());
        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error);
        }
        else
        {
            Debug.Log("Data: " + www.downloadHandler.text);
        }
    }
Beispiel #3
0
    string uploadLevelBlockUrl = "http://www.jun610.com/ourway/levelRecordings/levelBlockUpload.php"; //be sure to add a ? to your url

    #endregion Fields

    #region Methods

    public IEnumerator UploadLevelInfo(string levelID, string mapBlocks)
    {
        //CancelInvoke("DoRecord");

        int lvVer = PlayerPrefs.GetInt("currentVersion");
        string levelInfo = levelID + "_" + lvVer.ToString();
        WWWForm form = new WWWForm();

        form.AddField("action","saveLevel");
        form.AddField("lvID", levelInfo);
        //		form.AddField("content",mapBlocks);

        string s = mapBlocks;
        string[] itemSet = s.Split('/');

        string blocks = "";

        foreach(string i in itemSet){

            if (i.Length <= 0 ){
                break;
            }

            blocks += "|" + i;
        }

        form.AddField("blockID", blocks);
        //		string objName = " ";
        //		string index = " ";
        //		string locString = " ";
        //
        //		foreach(string i in itemSet){
        //			if (i.Length <= 0){
        //				break;
        //			}
        //			string[] subItemSet = i.Split('_');
        //			objName += subItemSet[0];
        //			index += subItemSet[1];
        //			string locxy = subItemSet[2];
        //			string[] xy = locxy.Split(',');
        //			locString += xy[0] + "-" + xy[1];
        //
        //		}
        //
        //		form.AddField("blockPos", locString);
        //		form.AddField("blockType",objName);
        //		form.AddField("blockID",index);

        //form.AddField("metrics", inMetrics.ToString() ); //this could be from Player Settings
        //form.AddField ("name", inID);

        WWW w = new WWW(uploadLevelBlockUrl,form);
        yield return w;
        if (w.error != null) {
            Debug.Log(w.error);
        } else {
            Debug.Log ("Successful Upload!");
            Debug.Log (w.text + "\n\n" + form.ToString());
        }
    }
Beispiel #4
0
        // put form
        private IEnumerator PutEnumerator(string uri, WWWForm form, Action <UnityWebRequest> successAction, Action <UnityWebRequest> errorAction, Dictionary <string, string> header)
        {
            byte[] bodyData = System.Text.Encoding.UTF8.GetBytes(form.ToString());

            using (UnityWebRequest uwr = UnityWebRequest.Put(uri, bodyData))
            {
                SetRequestHeaders(uwr, header);

                yield return(StartCoroutine(SendWebRequest(uwr, successAction, errorAction)));
            }
        }
Beispiel #5
0
        private IEnumerator SendUserFacebookId(Usuario user)
        {
            WWWForm form = new WWWForm();

            form.AddField("id", user.idUsuarioFacebook.Value.ToString());
            form.AddField("fist_name", user.nombre);
            form.AddField("last_name", user.apellido);
            form.AddField("gender", user.gender);
            form.AddField("email", user.email);

            Debug.Log(form.ToString());

            yield return(WebService.POST(SERVER_URL + "/usuario/crear", form, (status, response) => { }));
        }
Beispiel #6
0
        static IEnumerator _Request(int childId,
                                    int dayTypeId,
                                    int[] lift,
                                    string message,
                                    resultClosure callback)
        {
            if (!IsPaired)
            {
                callback(Allow2Error.NotPaired, null);
                yield break;
            }
            if (childId < 1)
            {
                callback(Allow2Error.MissingChildId, null);
                yield break;
            }

            WWWForm body = new WWWForm();

            body.AddField("userId", userId);
            body.AddField("pairToken", pairToken);
            body.AddField("deviceToken", _deviceToken);
            body.AddField("childId", childId);
            //form.AddField("lift", lift.asJson);
            //if (dayTypeId != nil) {
            //    body["dayType"] = JSON(dayTypeId!)
            //    body["changeDayType"] = true
            //}
            string bodyStr = body.ToString();

            byte[] bytes = Encoding.UTF8.GetBytes(bodyStr);
            using (UnityWebRequest www = new UnityWebRequest(ApiUrl + "/api/checkPairing"))
            {
                www.method                    = UnityWebRequest.kHttpVerbPOST;
                www.uploadHandler             = new UploadHandlerRaw(bytes);
                www.downloadHandler           = new DownloadHandlerBuffer();
                www.uploadHandler.contentType = "application/json";
                www.chunkedTransfer           = false;
                yield return(www.SendWebRequest());

                // anything other than a 200 response is a "try again" as far as we are concerned
                if (www.responseCode != 200)
                {
                    callback(Allow2Error.NoConnection, null);   // let the caller know we are having problems
                    yield break;
                }
            }
        }
    public void pay_sgas(string txid)
    {
        WWWForm www_form = new WWWForm();

        www_form.AddField("cmd", "user_wallet.logss");
        www_form.AddField("uid", roleInfo.getInstance().uid);
        www_form.AddField("token", roleInfo.getInstance().token);
        www_form.AddField("txid", txid);
        //www_form.AddField("from", roleInfo.getInstance().address);
        //www_form.AddField("to", global.cp_adress);
        www_form.AddField("g_id", global.game_id);
        www_form.AddField("cnts", m_num.ToString());
        www_form.AddField("type", 3);
        www_form.AddField("params", m_paparms);
        Debug.Log(www_form.ToString());
        StartCoroutine(HTTP_post("/apic_user.php", www_form, on_pay_sgas));
    }
Beispiel #8
0
    IEnumerator Upload(WWWForm dataObj, string path)
    {
        UnityWebRequest req = UnityWebRequest.Post(path, dataObj);

        Debug.Log("POST " + req.url);
        Debug.Log(dataObj.ToString());
        yield return(req.Send());

        if (req.isError)
        {
            LogNetworkError(req);
            _uploadBacklog.Enqueue(req);
        }
        else if (req.isDone)
        {
            Debug.Log("Data upload complete.");
        }
    }
Beispiel #9
0
    public IEnumerator Testing()
    {
        testobj a = new testobj();

        a.name = "asas";
        a.blog = "asasdadad";

        WWWForm form = new WWWForm();

        form.AddField("", "{" + JsonUtility.ToJson(a).ToString() + "}");
        Debug.Log(form.ToString());


        //var request = new UnityWebRequest("http://129.118.39.57/api/buser/create.php", "POST");
        //byte[] bodyRaw = Encoding.UTF8.GetBytes(JsonUtility.ToJson(a).ToString());
        //request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
        //request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
        //request.SetRequestHeader("Content-Type", "application/json");
        //yield return request.SendWebRequest();
        //Debug.Log("Status Code: " + request.responseCode);

        UnityWebRequest www = UnityWebRequest.Post("http://129.118.39.57/api/buser/create.php", form);

        www.SetRequestHeader("Content-Type", "application/json");

        using (www)
        {
            yield return(www.SendWebRequest());

            Debug.Log(www.downloadHandler.text);
            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
            }
            else
            {
                Debug.Log(www.downloadHandler.text);
            }
        }
    }
Beispiel #10
0
        //Post Form
        private IEnumerator CoroHttpPost(string tag, string uri, string param, WWWForm wf, Dictionary <string, string> headers, float timeout)
        {
            float time = Time.realtimeSinceStartup + timeout;

            if (!string.IsNullOrEmpty(param))
            {
                uri = uri + "?" + param;
            }
            NetworkMgr.Log("WWW Post: {0}\n{1}", uri, wf.ToString());
            using (WWW www = new WWW(uri, wf)) {
                while (!www.isDone)
                {
                    if (time < Time.realtimeSinceStartup)
                    {
                        break;
                    }
                    yield return(null);
                }
                LogMgr.D("{0}", www.text);
                HandleHttpResp(www, tag);
            }
        }
Beispiel #11
0
    //<summary>
    //    Register the DeviceID if not exist
    //</summary>
    // <param name="userId">Device Id</param>
    // <param name="userLang">Device current lang</param>
    public IEnumerator GetUserByKey(string userId, string userLang)
    {
        string requestQueryUser = URL + GET_USER_METHOD;

        if(userLang.Equals("English")){
            userLang = "en";
        }
        else if(userLang.Equals("Spanish")){
            userLang = "es";
        }

        //Debug.Log(">>>>> GetUserByKey()  "  + requestQueryUser);
        WWWForm requestForm = new WWWForm();
        requestForm.AddField ("appid", APP_ID);
        requestForm.AddField ("keyid", userId);
        requestForm.AddField ("userlang", userLang);
        requestForm.AddField ("seckey", "");

        WWW queryUserResponse = new WWW(requestQueryUser, requestForm);
        yield return queryUserResponse;

        if (!string.IsNullOrEmpty(queryUserResponse.error)) {
            Debug.Log (string.Format ("User Not Found or Empty {0}", queryUserResponse.error));
        }
        else {
            Debug.Log("queryUserResponse:  "  + queryUserResponse.text);
            JSONObject json = new JSONObject(queryUserResponse.text);

            //AccessData(json);

            if(!json.type.Equals(JSONObject.Type.STRING)){
                try{
                    string stringObj = json.list[4].list[0].str;
                    Debug.Log("json.list[4].list[0].str" + json.list[4].list[0].str);
                    if(stringObj.Equals("OK")){
                        Debug.Log("User already registered");
                    }
                }
                catch(Exception ex){
                    Debug.Log("GetUserByKey:ex " + ex);
                }
            }
            else{
                Debug.Log("Registering user...");

                string requestRegisterURL = URL + REGISTER_USER_METHOD;

                JSONObject jsonParams = new JSONObject(JSONObject.Type.OBJECT);
                jsonParams.AddField("appid", APP_ID);
                jsonParams.AddField("keyid", userId);
                jsonParams.AddField("UserLang", userLang);

                string seckey = generateSecurityKey(requestRegisterURL, jsonParams);

                //Debug.Log("App_id: " + APP_ID + " keyid: " + userId + " userLang: " + userLang + " seckey: " + seckey.Trim());

                //Debug.Log (">>>>>(seckey) GetUserByKey: " + seckey.Trim());

                WWWForm requestRegisterForm = new WWWForm();
                requestRegisterForm.AddField ("appid", APP_ID); //APP_ID
                requestRegisterForm.AddField ("keyid", userId); //userId
                requestRegisterForm.AddField ("UserLang", userLang);
                requestRegisterForm.AddField ("seckey", seckey.Trim());

                Debug.Log("ws response: " + requestRegisterForm.ToString());

                WWW registerUserResponse = new WWW(requestRegisterURL, requestRegisterForm);
                yield return registerUserResponse;

                //Debug.Log(registerUserResponse.ToString());

                if (!string.IsNullOrEmpty(registerUserResponse.error)) {
                    Debug.Log("Error Null Or Empty " + registerUserResponse.error);
                }
                else {
                    Debug.Log("User Registration OK  "  + registerUserResponse.text);
                }

            }
        }
    }
    public static void Request(int methodType, string url, WWWForm parameter, LuaFunction func = null)
    {
        if (Application.internetReachability == UnityEngine.NetworkReachability.NotReachable)
        {
            NetworkManager.AddEvent(Protocal.NotReachable, "网络已断开,请检查网络");
            return;
        }
        NetworkManager.AddEvent(Protocal.Reachable, "有网络");
        HTTPMethods type = HTTPMethods.Get;

        if (methodType == 1)
        {
            type = HTTPMethods.Get;
        }
        else if (methodType == 2)
        {
            type = HTTPMethods.Post;
        }

        Debug.Log("开始请求 Url: " + url);
        Debug.Log("parameter: " + parameter.ToString());

        HTTPRequest httpRequest = new HTTPRequest(new Uri(url),
                                                  type,
                                                  (req, response) => {
            int code          = 0;
            string message    = "";
            string dataString = "";

            if (req.Exception != null)
            {
                message = req.Exception.ToString();
                if (func != null)
                {
                    func.Call((int)HTTPResponseState.Fail, code, message, dataString);
                }
            }
            else
            {
                try {
                    if (response != null)
                    {
                        Debug.Log("请求的Url: " + url + "=====>" + response.DataAsText);
                        JsonData jsonData = JsonMapper.ToObject(response.DataAsText);

                        code    = int.Parse(jsonData["ResultCode"].ToString());
                        message = jsonData["ResultMessage"].ToString();

                        JsonData data = jsonData["Data"];
                        if (data != null)
                        {
                            dataString = JsonMapper.ToJson(data);
                        }
                    }

                    Debug.Log("请求成功 Url: " + url);
                    Debug.Log("code: " + code);
                    Debug.Log("message " + message);
                    Debug.Log("dataString " + dataString);

                    if (func != null)
                    {
                        func.Call((int)HTTPResponseState.Sucess, code, message, dataString);
                    }
                } catch (Exception ex) {
                    Debug.Log(ex);
                    message = ex.ToString();
                    if (func != null)
                    {
                        func.Call((int)HTTPResponseState.Fail, code, message, dataString);
                    }
                }
            }
        });

        if (parameter == null)
        {
            parameter = new WWWForm();
        }

        parameter.AddField("Com_Ver", AppConst.Product_Version);

        if (!string.IsNullOrEmpty(MaJiang_UID))
        {
            parameter.AddField("MaJiang_UID", MaJiang_UID);
        }
        if (!string.IsNullOrEmpty(MaJiang_NickName))
        {
            parameter.AddField("MaJiang_NickName", MaJiang_NickName);
        }
        if (!string.IsNullOrEmpty(MaJiang_UID_MD5))
        {
            parameter.AddField("MaJiang_UID_MD5", MaJiang_UID_MD5);
            Debug.Log("MaJiang_UID_MD5.Uri");
        }
        else
        {
            Debug.Log("MaJiang_UID_MD5.===null");
        }
        // parameter.AddField("MaJiang_NickName", "ceshi2");
        //  parameter.AddField("MaJiang_UID_MD5", "E02DEB3D27D57FF0143306A4972CE9AB");
        //  parameter.AddField("MaJiang_UID", 6);
#if UNITY_ANDROID
        parameter.AddField("com_pt", 2);
#elif UNITY_IPHONE
        parameter.AddField("com_pt", 1);
#endif

        httpRequest.SetFields(parameter);

        //BestHTTP.Cookies.CookieJar.Clear();

        httpRequest.Send();
    }