Esempio n. 1
0
        private void btnWininet_Click(object sender, EventArgs e)
        {
            Random  r    = new Random();
            Wininet wnet = new Wininet();

            pic.Image = wnet.GetImage(picurl);
        }
Esempio n. 2
0
        private void button5_Click(object sender, EventArgs e)//测试创建pid
        {
            //解析cookie中用于参数的字段
            CookieContainer cookieCollectionByString = MyCookie.GetCookieCollectionByString(DT.Cookie, "pub.alimama.com");

            StringBuilder header = new StringBuilder();

            header.Append("User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36\r\n");
            header.Append("Content-Type:application/x-www-form-urlencoded; charset=UTF-8\r\n");
            header.Append("Accept:application/json, text/javascript, */*; q=0.01\r\n");
            header.Append("Accept-Encoding:gzip, deflate\r\n");
            header.Append("Accept-Language:zh-CN,zh;q=0.8\r\n");
            header.Append("Host: pub.alimama.com\r\n");
            header.Append("Origin:http://pub.alimama.com\r\n");
            header.Append("X-Requested-With:XMLHttpRequest\r\n");
            header.Append("Cookie:" + DT.Cookie);
            Wininet       wininet  = new Wininet();
            StringBuilder postData = new StringBuilder("tag=29&gcid=0&siteid=40968507&selectact=add&newadzonename=test&t=" + DateTool.GetCurrentTimeStamp() + "&_tb_token_=" + MyCookie.GetCookie("_tb_token_", cookieCollectionByString));

            Console.WriteLine("当前post数据:" + postData.ToString());

            String responseBody = wininet.PostData("http://pub.alimama.com/common/adzone/selfAdzoneCreate.json", postData.ToString(), header);

            Console.WriteLine("响应内容:" + responseBody);
        }
Esempio n. 3
0
        private void button7_Click(object sender, EventArgs e)
        {
            Wininet       wi = new Wininet();
            StringBuilder sb = new StringBuilder();

            sb.Append("Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n");
            sb.Append("Content-Type:application/x-www-form-urlencoded\r\n");
            sb.Append("Accept-Language:zh-cn\r\n");
            sb.Append("Referer:" + "http://mrtx.u193.com/");//增加referer头
            string str = wi.PostData("http://www.u193.com/opt.php?do=login", "username=ceshiyixia1&password=111111", sb);

            str = wi.GetData("http://mrtx.u193.com/");
        }
        public static String getProxyIpAndPort()
        {
            Wininet wininet = new Wininet();
            String  result  = wininet.GetData("http://api.ip.data5u.com/dynamic/get.html?order=61fbc26a3a7cd3f62bf8be2e7a60c83a&ttl=1&sep=3");

            //返回的格式 222.185.146.193:39441,16361
            if (result.Contains(","))
            {
                return(result.Split(',')[0]);
            }
            else
            {
                return(result);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Retrieves the connected state of the local system.
        /// </summary>
        /// <returns>The connected state of the local system.</returns>
        public static NetworkConnState GetNetworkConnectState()
        {
            uint lpdwFlags;

            if (Wininet.InternetGetConnectedState(out lpdwFlags, 0))
            {
                if ((lpdwFlags & InetFlags.INTERNET_CONNECTION_MODEM) != 0)
                {
                    return(NetworkConnState.ONLINE_MODEM);
                }
                else if ((lpdwFlags & InetFlags.INTERNET_CONNECTION_LAN) != 0)
                {
                    return(NetworkConnState.ONLINE_LAN);
                }
            }
            return(NetworkConnState.OFFLINE);
        }
Esempio n. 6
0
        private void btnProxy_Click(object sender, EventArgs e)
        {
            string    url  = "http://1111.ip138.com/ic.asp"; //请求地址
            string    ip   = "127.0.0.1:8888";               //设置代理IP地址
            HttpItems item = new HttpItems();

            item.URL     = url;
            item.ProxyIp = ip;
            //如果代理服务器需要用户名与密码请参考此设置
            //item.ProxyUserName = "******";//如果代理服务器需要用户名
            //item.ProxyPwd = "密码";//如果代理服务器需要密码
            HttpResults hr = http.GetHtml(item);
            // hr.Html; 请求具体结果
            Wininet winet = new Wininet();
            //Post
            string postdata = "GetHtmlPro 如果传入PostData参数则认为当前是Post请求";
            string Posthtml = winet.GetDataPro(winet.GetHtmlPro(url, postdata, ip));
            //Get
            string Gethtml = winet.GetDataPro(winet.GetHtmlPro(url, "", ip));
            //使用代理请求图片时
            Image img = winet.GetImage(winet.GetHtmlPro("图片URL", "", ip));
        }
Esempio n. 7
0
        /// <summary>Run the SMA update process</summary>
        /// <returns></returns>
        public async Task Update()
        {
            // TODO: Add option to wait for user confirmation to update

            if (UpdateEnabled == false)
            {
                return;
            }

            ReleaseEntry updateVersion = null;

            try
            {
                if (Wininet.HasNetworking() == false)
                {
                    return;
                }

                CancellationTokenSource cts = new CancellationTokenSource(0);
                cts.Cancel();

                using (await Semaphore.LockAsync(cts.Token))
                    using (var updateMgr = CreateUpdateMgr())
                    {
                        State = SMAUpdateState.Fetching;

                        var updateInfo = await updateMgr.CheckForUpdate(
                            true,
                            false,
                            progress => ProgressPct = progress,
                            UpdaterIntention.Update,
                            UpdateMinPrerelease);

                        if (updateInfo?.ReleasesToApply == null)
                        {
                            State = SMAUpdateState.Error;
                            return;
                        }

                        if (updateInfo.ReleasesToApply.None())
                        {
                            State = SMAUpdateState.UpToDate;
                            return;
                        }

                        updateVersion = updateInfo.FutureReleaseEntry;

                        State = SMAUpdateState.Downloading;

                        await updateMgr.DownloadReleases(updateInfo.ReleasesToApply, progress => ProgressPct = progress);

                        State = SMAUpdateState.Applying;

                        await updateMgr.ApplyReleases(updateInfo, progress => ProgressPct = progress);

                        State = SMAUpdateState.CreatingUninstaller;

                        await updateMgr.CreateUninstallerRegistryEntry();

                        State = SMAUpdateState.Updated;
                    }
            }
            catch (TaskCanceledException) { }
            catch (Exception ex) // TODO: Update Squirrel UpdateManager to send sub-classed Exceptions
            {
                LogTo.Warning(ex, "An exception was caught while {V} update", State.Name().ToLower(CultureInfo.InvariantCulture));
                State = SMAUpdateState.Error;
            }
            finally
            {
                Semaphore.Release();

                if (updateVersion != null)
                {
                    NotifyUpdateResult(updateVersion);
                }
            }
        }
Esempio n. 8
0
        public async Task Update()
        {
            // TODO: Ensure only one Update is running across all instances of SMA (in case SMA is closed during the update process)
            // TODO: Offer manual updates
            // TODO: Add option to wait for user confirmation to update

            if (UpdateEnabled == false)
            {
                return;
            }

            try
            {
                if (Wininet.HasNetworking() == false)
                {
                    return;
                }

                CancellationTokenSource cts = new CancellationTokenSource(0);
                cts.Cancel();

                using (await _semaphore.LockAsync(cts.Token))
                    using (var updateMgr = CreateUpdateMgr())
                    {
                        State = SMAUpdateState.Fetching;

                        var updateInfo = await updateMgr.CheckForUpdate(false, progress => ProgressPct = progress);

                        if (updateInfo?.ReleasesToApply == null)
                        {
                            State = SMAUpdateState.Error;
                            return;
                        }

                        if (updateInfo.ReleasesToApply.None())
                        {
                            State = SMAUpdateState.UpToDate;
                            return;
                        }

                        State = SMAUpdateState.Downloading;

                        await updateMgr.DownloadReleases(updateInfo.ReleasesToApply, progress => ProgressPct = progress);

                        State = SMAUpdateState.Applying;

                        await updateMgr.ApplyReleases(updateInfo, progress => ProgressPct = progress);

                        State = SMAUpdateState.CreatingUninstaller;

                        await updateMgr.CreateUninstallerRegistryEntry();

                        State = SMAUpdateState.Updated;
                    }
            }
            catch (TaskCanceledException) {}
            catch (Exception ex) // TODO: Update Squirrel UpdateManager to send sub-classed Exceptions
            {
                LogTo.Warning(ex, $"An exception was caught while {State.Name().ToLower()} update");
                State = SMAUpdateState.Error;
            }
            finally
            {
                _semaphore.Release();
            }
        }