コード例 #1
0
        public static void Run(FMWW.Http.Client client, Uri address)
        {
            var text = "";

            while (!IsFin(text))
            {
                var resData = client.UploadValues(address, CreateAjaxQuery());
                text = Encoding.UTF8.GetString(resData);
                if (HasError(text))
                {
                    throw new Exception(SnipError(text));
                }
            }
        }
コード例 #2
0
        public void SignIn(FMWW.Http.Client client, string username, string password, string person, string personPassword)
        {
            //            this.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
            Stream       data   = client.OpenRead(UrlToSignIn);
            StreamReader reader = new StreamReader(data, Encoding.UTF8);
            var          html   = reader.ReadToEnd();

            data.Close();
            reader.Close();

#if false
            //            var setCookie = this.ResponseHeaders[HttpResponseHeader.SetCookie];
            //            var cookies = System.Text.RegularExpressions.Regex.Split(setCookie, "(?<!expires=.{3}),")
            //    .Select(s => s.Split(';').First().Split('='))
            //    .Select(xs => new { Name = xs.First(), Value = string.Join("=", xs.Skip(1).ToArray()) })
            //    .Select(a => a.Name + "=" + a.Value)
            //    .ToArray();
            //            var cookie = string.Join(";", cookies);
            //            this.Headers[HttpRequestHeader.Cookie] = cookie;
#endif


            NameValueCollection form = BuildQueryToSignIn(html, username, password, person, personPassword);

            //            this.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
            byte[] resData = client.UploadValues(UrlToSignIn, form);
            //            _html = System.Text.Encoding.GetEncoding("Shift_JIS").GetString(resData);
            html = Encoding.UTF8.GetString(resData);
            Debug.WriteLine(html);
            if (null == GetBtnLogOff(html))
            {
                throw new Exception();
            }

            /*
             *          this.OpenReadCompleted += (sender, e) =>
             *              {
             *                  if (e.Error != null)
             *                  {
             *                      // エラー処理
             *                  }
             *
             *                  var data = e.Result;
             *                  // Do Something
             *                  if (!(data is System.IO.Stream))
             *                  {
             *                      return;
             *                  }
             *                  if (!(sender is WebClient))
             *                  {
             *                      return;
             *                  }
             * //                    WebClient wc = sender as WebClient;
             *
             *                  foreach (string key in client.ResponseHeaders.Keys)
             *                  {
             *                      System.Diagnostics.Debug.WriteLine(String.Format(@"{0}:{1}", key, client.ResponseHeaders[key]));
             *                  }
             *
             *              };
             * */
        }