ApexLumia.HTTPRequests.getRequestAsync C# (CSharp) Метод

getRequestAsync() публичный статический Метод

Async: Make an HTTP GET request to a URL (with no extra parameters)
public static getRequestAsync ( string url ) : Task
url string The URL you would like to send a request to.
Результат Task
        public static async Task<String> getRequestAsync(string url)
        {
            string result = "";

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                WebResponse response = await request.GetResponseAsync();
                result = new StreamReader(response.GetResponseStream()).ReadToEnd();
            }
            catch { return ""; }

            return result;
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Async: Get a new, randomly generated UUID from the CouchDB itself for use in new documents.
        /// </summary>
        /// <returns></returns>
        private async Task <string> getNewUUID()
        {
            string url           = _databaseurl + "_uuids";
            string retrievedJSON = await HTTPRequests.getRequestAsync(url);

            Dictionary <string, string[]> json;
            string newUUID = "";

            try
            {
                json    = JsonConvert.DeserializeObject <Dictionary <string, string[]> >(retrievedJSON);
                newUUID = json["uuids"][0];
            }
            catch
            { return(""); }

            return(newUUID);
        }