Exemple #1
0
        private void POSTRequestSetup(RESTRequest rr)
        {
            if (rr.IsRawBytes())
            {
                rr.AddHeader("Content-type", "application/json");
            }
            else
            {
                rr.AddHeader("Content-type", "application/x-www-form-urlencoded");
            }

            if (rr.Method() != HTTPMethod.POST)
            {
                rr.AddHeader("X-HTTP-Method-Override", rr.Method().ToString());
            }

            if (rr.IsRawBytes())
            {
                rr.requestData = new WWW(this.Endpoint(), rr.GetRawBytes(), rr.GetHeaders());
            }
            else
            {
                rr.requestData = new WWW(this.Endpoint(), rr.PostParameters().data, rr.GetHeaders());
            }
        }
Exemple #2
0
        /// <summary>
        /// Sends a constructed RESTRequest to the client's endpoint. Must be called inside a coroutine -
        /// the returned data will be stored in the RESTRequest.
        /// </summary>
        /// <param name="rr">The request to be sent.</param>
        /// <returns></returns>
        public IEnumerator sendRequest(RESTRequest rr)
        {
            Debug.Log("started data download");

            rr.Start();

            switch (rr.Method())
            {
            case HTTPMethod.GET:
                GETRequestSetup(rr);
                break;

            case HTTPMethod.POST:
                POSTRequestSetup(rr);
                break;

            case HTTPMethod.PUT:
                POSTRequestSetup(rr);
                break;

            case HTTPMethod.DELETE:
                POSTRequestSetup(rr);
                break;

            default: break;
            }

            yield return(rr.requestData);

            rr.retrieveCallback()(rr.GetData());
            rr.Finish();

            Debug.Log("data download finished");
        }