예제 #1
0
    private void SubmitName(string arg0)
    {
        Text output = receive_output.GetComponent <Text>();

        output.text = "connecting to server...";
        AsyncWebRequest.Post(server_api, arg0, UpdateResponseText, this);
        //Debug.Log(arg0);
    }
예제 #2
0
        /// <summary>
        /// Sends a request
        /// </summary>
        /// <param name="uri">The full URI of the request</param>
        /// <param name="method">The request method (GET/POST)</param>
        /// <param name="form">A WWWForm to include with the request</param>
        /// <param name="onFinished">Called when the request is finished</param>
        /// <param name="silent">Whether or not to log errors while making the request</param>
        /// <returns></returns>
        public IEnumerator makeRequestAsync(string uri, string method, WWWForm form = null, Action <string> onFinished = null, bool silent = false)
        {
            ErrorMessage    = null;
            IsDoneUploading = false;
            UploadError     = false;
            UploadException = null;

            AsyncWebRequest request = new AsyncWebRequest();

            if (method == "GET")
            {
                yield return(request.Get(uri));
            }
            else if (method == "POST")
            {
                yield return(request.Post(uri, form));
            }
            else
            {
                UploadError  = true;
                ErrorMessage = "Unsupported request method: " + method;

                if (!silent)
                {
                    Debug.LogError("Error making request to Trello API!");
                    Debug.LogError(ErrorMessage);
                }

                yield break;
            }

            IsDoneUploading = true;

            string response = null;

            if (request.UploadException != null)
            {
                UploadException = request.UploadException;
                UploadError     = true;
                ErrorMessage    = "Error making request to Trello API!";

                // log error
                if (!silent)
                {
                    Debug.LogError("Error Making Request to Trello API!");
                    Debug.LogException(request.UploadException);
                }
            }
            else if (request.Request.responseCode != (long)HttpStatusCode.OK && !silent)
            {
                UploadError  = true;
                ErrorMessage = "Trello API: Error " + request.Request.responseCode;

                // log error
                if (!silent)
                {
                    Debug.LogError("Error Making Request to Trello API!");
                    Debug.LogError("Status Code " + request.Request.responseCode + ": " + request.Request.downloadHandler.text);
                }
            }
            else if (request.RequestIsError && !silent)
            {
                UploadError  = true;
                ErrorMessage = "Error making request to Trello API!";

                // log error
                if (!silent)
                {
                    Debug.LogError("Error Making Request to Trello API!");
                    Debug.LogError(request.Request.error);
                }
            }
            else
            {
                // get response text
                response = request.Request.downloadHandler.text;
            }

            // handle callback
            if (onFinished != null)
            {
                onFinished(response);
            }
        }
예제 #3
0
 // Use this for initialization
 void Start()
 {
     //AsyncWebRequest.Get("http://*****:*****@"{""test"":""test1""}", printWebResponse, this);
     //print (@"{""test"":""test1""}");
 }