Exemplo n.º 1
0
 /// <summary>
 /// Delete the specified resource
 /// </summary>
 /// <param name="url"></param>
 /// <param name="encodedId">The user's base64 encoded user ID</param>
 /// <returns></returns>
 public async Task <HttpResponseMessage> DeleteData(string url, string encodedId)
 {
     using (var client = new HttpClient())
     {
         string token = JsonWebTokenServices.CreateJsonWebtoken();
         client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(WebServiceConstants.Subscriber, token);
         client.DefaultRequestHeaders.Add("WebRequestUserID", encodedId);
         return(await client.DeleteAsync(new Uri(url)));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Posts HTTP data to the specified endpoint
        /// </summary>
        /// <param name="url"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public async Task <HttpResponseMessage> PostData(string url, HttpContent content)
        {
            string token = JsonWebTokenServices.CreateJsonWebtoken();

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Authorization =
                    new AuthenticationHeaderValue(WebServiceConstants.Subscriber, token);
                return(await client.PostAsync(new Uri(url), content));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves data from the specified endpoint
        /// </summary>
        /// <param name="url"></param>
        /// <param name="encodedId">The user's base64 encoded user ID.
        /// N.B. Not needed when initially retrieveing the user's information.</param>
        /// <returns></returns>
        public async Task <string> GetData(string url, string encodedId = null)
        {
            using (var client = new HttpClient())
            {
                string token = JsonWebTokenServices.CreateJsonWebtoken();
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(WebServiceConstants.Subscriber, token);
                if (!string.IsNullOrEmpty(encodedId))
                {
                    client.DefaultRequestHeaders.Add("WebRequestUserID", encodedId);
                }
                using (var r = await client.GetAsync(new Uri(url)))
                {
                    string result = await r.Content.ReadAsStringAsync();

                    return(result);
                }
            }
        }