Ejemplo n.º 1
0
        /// <summary>
        /// Performs login to the server
        /// </summary>
        /// <param name="login">String with user's telephone number</param>
        /// <param name="pwd">String with user's password</param>
        /// <returns></returns>
        public bool Login(string login, string pwd)
        {
            try
            {
                string loginData = string.Format(
                        "usuario={0}&clave={1}&submit.x=36&submit.y=6",
                        login,
                        pwd
                        );

                // Login
                HttpWebResponse response = HttpHelper.ExecuteRequest(
                    "http://www.localizame.movistar.es/login.do",
                    "application/x-www-form-urlencoded",
                    "POST",
                    loginData,
                    null,
                    false
                    );

                if (response == null)
                {
                    _lastError = "Unable to connect web service";
                    return false;
                }
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    _lastError = ((int)response.StatusCode).ToString() + " " + response.StatusDescription;
                    return false;
                }

                string responseData = HttpHelper.ReadBody(response, System.Text.Encoding.Default);
                if (responseData.IndexOf("Acceso Restringido") > -1)
                {
                    _lastError = "Restricted Access";
                    return false;
                }

                /*
                FileStream fs = new FileStream("c:\\aa.txt", FileMode.Create, FileAccess.Write);
                fs.Write(responseData, 0, responseData.Length);
                fs.Close();
                */

                _cookie = response.Headers["Set-Cookie"];
                if (_cookie == null)
                {
                    _lastError = "Cookie not found!";
                    return false;
                }

                HttpHelper.Header[] headers = new HttpHelper.Header[]{new HttpHelper.Header("Referer","http://www.localizame.movistar.es/login.do"),new HttpHelper.Header("Cookie",_cookie)};

                // NewUser page access
                response = HttpHelper.ExecuteRequest(
                    "http://www.localizame.movistar.es/nuevousuario.do",
                    "",
                    "GET",
                    null,
                    headers,
                    false
                    );

                if (response == null)
                {
                    _lastError = "Unable to connect web service";
                    return false;
                }
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    _lastError = ((int)response.StatusCode).ToString() + " " + response.StatusDescription;
                    return false;
                }

                return true;
            }
            catch (Exception ex)
            {
                _lastError = "Internal Error: " + ex.Message;
                return false;
            }
        }
Ejemplo n.º 2
0
        private XmlDocument doSMS20Request(string data, ref bool responseEmpty)
        {
            responseEmpty = false;

            HttpHelper.Header[] headers = new HttpHelper.Header[] { new HttpHelper.Header("Accept-Encoding", "identity"), new HttpHelper.Header("Expect", "100-continue") };
            HttpWebResponse response = HttpHelper.ExecuteRequest(
                "http://sms20.movistar.es/",
                "application/vnd.wv.csp.xml",
                "POST",
                data,
                null,
                false
                );

            if (response == null)
            {
                _lastError = "Unable to contact web service";
                return null;
            }

            if (response.StatusCode != HttpStatusCode.OK)
            {
                _lastError = "Server error: " + ((int)response.StatusCode).ToString() + " " + response.StatusDescription;
                return null;
            }
            if (response.ContentLength <= 0)
            {
                responseEmpty = true;
                return null;
            }
            else
            {
                XmlDocument doc = HttpHelper.ReadBodyAsXml(response);
                if (doc == null)
                {
                    _lastError = "Bad xml";
                    return null;
                }
                return doc;
            }
        }