コード例 #1
0
ファイル: WebRequester.cs プロジェクト: CodeFork/PureLib
        private string RequestInternal(Uri uri, string method, byte[] data, string contentType)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);

            req.CookieContainer   = Cookies;
            req.UserAgent         = UserAgent;
            req.AllowAutoRedirect = AllowAutoRedirect;
            req.Referer           = Referer;
            req.Method            = method;
            req.ContentType       = contentType;
            SetRequest?.Invoke(this, new EventArgs <HttpWebRequest>(req));

            if ((data != null) && data.Any() && (method != WebRequestMethods.Http.Get) && (method != WebRequestMethods.Http.Head))
            {
                req.ContentLength = data.Length;
                using (Stream stream = req.GetRequestStream()) {
                    stream.Write(data, 0, data.Length);
                }
            }

            HttpWebResponse res = (HttpWebResponse)req.GetResponse();

            GotResponse?.Invoke(this, new EventArgs <HttpWebResponse>(res));
            using (StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding)) {
                return(sr.ReadToEnd());
            }
        }
コード例 #2
0
ファイル: AdvancedWebClient.cs プロジェクト: CodeFork/PureLib
        protected override WebRequest GetWebRequest(Uri address)
        {
            HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);

            SetRequest?.Invoke(this, new EventArgs <HttpWebRequest>(request));
            return(request);
        }
コード例 #3
0
        private async Task <(bool, string)> RequestInternalAsync(Uri uri, HttpMethod httpMethod, byte[] data, string contentType)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);

            req.CookieContainer   = Cookies;
            req.UserAgent         = UserAgent;
            req.AllowAutoRedirect = AllowAutoRedirect;
            req.Referer           = Referer;
            req.Method            = httpMethod.Method;
            req.ContentType       = contentType;
            SetRequest?.Invoke(this, new EventArgs <HttpWebRequest>(req));

            if (data != null && data.Any() && (httpMethod != HttpMethod.Get) && (httpMethod != HttpMethod.Head))
            {
                req.ContentLength = data.Length;
                using (Stream stream = await req.GetRequestStreamAsync().ConfigureAwait(false)) {
                    await stream.WriteAsync(data, 0, data.Length).ConfigureAwait(false);
                }
            }

            HttpWebResponse res = (HttpWebResponse)(await req.GetResponseAsync().ConfigureAwait(false));

            GotResponse?.Invoke(this, new EventArgs <HttpWebResponse>(res));
            Stream responseStream = res.GetResponseStream();

            using (StreamReader sr = new StreamReader(responseStream, Encoding)) {
                string response = await sr.ReadToEndAsync().ConfigureAwait(false);

                return(IsSuccessStatusCode((int)res.StatusCode), response);
            }
        }
コード例 #4
0
        protected override WebRequest GetWebRequest(Uri address)
        {
            HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);

            SetRequest?.Invoke(this, new EventArgs <HttpWebRequest>(request));

            long length = _uriContexts[address].CurrentFileLength;

            if (length > 0)
            {
                request.AddRange(length);
            }

            _uriContexts[address].Request = request;

            return(request);
        }
コード例 #5
0
ファイル: BusManager.cs プロジェクト: FireNGlory/smartwater
 protected virtual void OnSetRequest(int newTemp, string token)
 {
     SetRequest?.Invoke(this, new SetRequestEventArgs(newTemp, token));
 }