Exemplo n.º 1
0
        /// <summary>
        /// Sends a POST request to an API endpoint.</summary>
        /// <param name="url"> The URL of the API endpoint.</param>
        /// <param name="form"> When sending a POST request, you should create and populate a WWWForm object that defines the variables you are sending to the server.  If this parameter is not null, the request is assumed to be a POST request.  Otherwise it's a GET request.</param>
        /// <param name="timeout"> How long to wait for a response from the server before we give up.</param>
        /// <param name="webResponsePopulateDelegate"> This will be called when we have data back from the server, in order to allow us to populate response data into an object.  If you are calling a JSON API, you don't have to worry about this, since then you can just call either the SendGetRequest or SendPostRequest method, and it will take care of populating your response object for you.</param>
        /// <param name="onComplete"> This will be called when the request has completed (for both success and failure).</param>
        public string SendWebRequest <T>(string url, WWWForm form, float timeout
                                         , WebResponsePopulateDelegate webResponsePopulateDelegate, WebRequestFinishedDelegate onComplete)
        {
            // We're creating a unique identifier and passing it back out of this method so that upload progress can be tracked, if we're uploading a file.
            string requestIdentifier = Guid.NewGuid().ToString();

            WebRequestDetails webRequestDetails = new WebRequestDetails(url, form, timeout, typeof(T), webResponsePopulateDelegate, onComplete);

            webRequestDetails.MarkStartTime();
            _webRequests.Add(requestIdentifier, webRequestDetails);

            return(requestIdentifier);
        }
Exemplo n.º 2
0
 public WebRequestDetails(string url, WWWForm form, float timeout, Type responseObjectType
                          , WebResponsePopulateDelegate webResponsePopulateDelegate
                          , WebRequestFinishedDelegate webRequestFinishedDelegate)
 {
     if (form != null)
     {
         this.www = new WWW(url, form);
     }
     else
     {
         this.www = new WWW(url);
     }
     this.responseObject              = null;
     this.responseObjectType          = responseObjectType;
     this.startTime                   = 0.0f;
     this.timeout                     = timeout;
     this.webResponsePopulateDelegate = webResponsePopulateDelegate;
     this.webRequestFinishedDelegate  = webRequestFinishedDelegate;
 }