Esempio n. 1
0
        public bool tryFrilLogin()
        {
            /*revert,android_id,device_id,app_generated_idなどのパラメタはなくてもOKなので送らない*/
            Dictionary <string, string> param = new Dictionary <string, string>();

            param.Add("email", this.account.email);
            param.Add("password", this.account.password);
            string          url    = "https://api.fril.jp/api/v4/users/sign_in";
            FrilRawResponse rawres = postFrilAPI(url, param);

            if (rawres.error)
            {
                return(false);
            }
            try {
                dynamic resjson = DynamicJson.Parse(rawres.response);
                this.account.auth_token = resjson.auth_token;
                ////Logger.info("ログイン成功");
                return(true);
            }
            catch (Exception e) {
                ////Logger.info("ログイン失敗");
                return(false);
            }
        }
Esempio n. 2
0
        //FrilAPIをPOSTでたたく
        private FrilRawResponse postFrilAPI(string url, Dictionary <string, string> param)
        {
            FrilRawResponse res = new FrilRawResponse();

            try {
                string        text     = "";
                List <string> paramstr = new List <string>();
                int           num      = 0;
                foreach (KeyValuePair <string, string> p in param)
                {
                    string k = Uri.EscapeUriString(p.Key);
                    string v = Uri.EscapeUriString(p.Value);
                    if (num != 0)
                    {
                        text += "&";
                    }
                    text = text + (k + "=" + v);
                    num++;
                }
                byte[]         bytes = Encoding.ASCII.GetBytes(text);
                HttpWebRequest req   = (HttpWebRequest)WebRequest.Create(url);
                req.UserAgent = FrilAPI.USER_AGENT;
                req.Method    = "POST";
                //リクエストヘッダを付加
                req.ContentType   = "application/x-www-form-urlencoded; charset=utf-8";
                req.Accept        = "application/json";
                req.ContentLength = (long)bytes.Length;
                //クッキーコンテナの追加
                req.CookieContainer = this.cc;// new CookieContainer();
                //クッキーの追加
                //if (!string.IsNullOrEmpty(this.cookie_fril_session)) req.CookieContainer.Add(new Uri(url), new Cookie("_fril_session", this.cookie_fril_session));
                //プロキシの設定
                if (string.IsNullOrEmpty(this.proxy) == false)
                {
                    System.Net.WebProxy proxy = new System.Net.WebProxy(this.proxy);
                    req.Proxy = proxy;
                }
                //タイムアウト設定
                req.Timeout = 5000;
                //POST
                string content = "";
                var    task    = Task.Factory.StartNew(() => executePostRequest(ref req, bytes));
                task.Wait(10000);
                if (task.IsCompleted)
                {
                    content = task.Result;
                }
                else
                {
                    throw new Exception("Timed out");
                }
                if (string.IsNullOrEmpty(content))
                {
                    throw new Exception("webrequest error");
                }
                res.error    = false;
                res.response = content;
                //クッキー更新
                foreach (Cookie c in req.CookieContainer.GetCookies(new Uri(url)))
                {
                    if (c.Name.ToString() == "_fril_session")
                    {
                        this.cookie_fril_session = c.Value.ToString();
                    }
                }
                //Log.//Logger.Info("MercariPOSTリクエスト成功");
                req.Abort();
                return(res);
            }
            catch (Exception e) {
                return(res);
                //Log.//Logger.Error("MercariPOSTリクエスト成功");
            }
        }