コード例 #1
0
        protected DownloadFileInfo GetFile(string url, int timeout = Config.TIME_OUT)
        {
            WebClientEx web = new WebClientEx();

            web.ResetHeaders();
            return(new DownloadFileInfo(web, url));
        }
コード例 #2
0
        private bool CheckUrlContent()
        {
            bool isok = true;

            System.Threading.Thread.Sleep(1000);
            try {
                var webClient = new WebClientEx();
                foreach (var checkUrl in CheckUrls)
                {
                    webClient.ResetHeaders();
                    if (string.IsNullOrEmpty(checkUrl.ContainString))
                    {
                        webClient.DownloadData(checkUrl.Url);
                    }
                    else
                    {
                        var str = webClient.DownloadString(checkUrl.Url);
                        if (str.Contains(checkUrl.ContainString) == false)
                        {
                            isok = false;
                            break;
                        }
                    }
                }
            } catch (Exception e) {
                isok = false;
            }
            return(isok);
        }
コード例 #3
0
        //private string WebPost(string url, string json)
        //{
        //    WebClientEx web = new WebClientEx();
        //    web.ResetHeaders();
        //    //web.Headers.Add();
        //    web.Encoding = Encoding.UTF8;
        //    return web.UploadString(url, "POST", json);
        //}
        //private string WebPost(string url, object obj)
        //{
        //    var json = JsonConvert.SerializeObject(obj);
        //    WebClientEx web = new WebClientEx();
        //    web.ResetHeaders();
        //    web.Encoding = Encoding.UTF8;
        //    return web.UploadString(url, "POST", json);
        //}
        private string WebGet(string url)
        {
            WebClientEx web = new WebClientEx();

            web.ResetHeaders();
            web.Encoding = Encoding.UTF8;
            return(web.DownloadString(url));
        }
コード例 #4
0
        public List <T> LoadUrl(string address)
        {
            WebClientEx webClient = new WebClientEx();

            webClient.ResetHeaders();
            var html = webClient.DownloadString(address);

            return(LoadData(html));
        }
コード例 #5
0
        private string WebPost(string url, object obj)
        {
            var         json = JsonConvert.SerializeObject(obj);
            WebClientEx web  = new WebClientEx();

            web.ResetHeaders();
            web.Encoding = Encoding.UTF8;
            return(web.UploadString(url, "POST", json));
        }
コード例 #6
0
        private string WebPost(string url, string json)
        {
            WebClientEx web = new WebClientEx();

            web.ResetHeaders();
            //web.Headers.Add();
            web.Encoding = Encoding.UTF8;
            return(web.UploadString(url, "POST", json));
        }
コード例 #7
0
        private string WebUpload(string url, string filePath)
        {
            WebClientEx web = new WebClientEx();

            web.ResetHeaders();
            web.Encoding = Encoding.UTF8;
            var bytes = web.UploadFile(url, "POST", filePath);

            return(Encoding.UTF8.GetString(bytes));
        }
コード例 #8
0
        protected T Post <T>(string url, string post, int timeout = Config.TIME_OUT) where T : class
        {
            WebClientEx web = new WebClientEx();

            web.ResetHeaders();
            web.Encoding = Encoding.UTF8;
            web.SetTimeOut(timeout);
            var json = web.UploadString(url, "POST", post);

            return(Deserialize <T>(json));
        }
コード例 #9
0
        protected T PostFile <T>(string url, string file, object obj, int timeout = Config.TIME_OUT) where T : class
        {
            WebClientEx web = new WebClientEx();

            web.ResetHeaders();
            web.Encoding = Encoding.UTF8;
            web.SetTimeOut(timeout);
            var bytes = web.UploadFile(url, file);
            var json  = Encoding.UTF8.GetString(bytes);

            return(Deserialize <T>(json));
        }