Esempio n. 1
0
        public async Task <byte[]> PostFormAsync(string url, NameValueCollection parameters,
                                                 YamsterHttpMethod method = YamsterHttpMethod.Post)
        {
            using (var webClient = new WebClient())
            {
                webClient.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);

                string token = this.appContext.Settings.OAuthToken;
                webClient.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
                webClient.Headers.Add("Accept-Encoding", "gzip, deflate");
                webClient.Headers.Add("Authorization", String.Format("Bearer {0}", token));
                webClient.Headers.Add("User-Agent", userAgent);

                string absoluteUrl = buildAbsoluteUrl(url);

                Debug.WriteLine("PostFormAsync: " + method.ToString() + " " + url);
                return(await webClient.UploadValuesTaskAsync(absoluteUrl,
                                                             method.ToString().ToUpperInvariant(),
                                                             parameters));
            }
        }
Esempio n. 2
0
 public YamsterHttpRequest(string url, YamsterHttpMethod method = YamsterHttpMethod.Get)
 {
     this.Url    = url;
     this.Method = method;
 }
Esempio n. 3
0
 private bool sendParamsAsBody(YamsterHttpMethod method)
 {
     return(method == YamsterHttpMethod.Post || method == YamsterHttpMethod.Put || method == YamsterHttpMethod.Delete);
 }