Beispiel #1
0
        public IHttpService AddParameter(string type, string name, object value)
        {
            var adaptedValue =
                value is decimal?value.ToString().Replace(".", "").Replace(",", ".") : value.ToString();

            switch (type)
            {
            case "Body":
                Body = value;
                break;

            case "FormBody":
                FormBody.Add(name, adaptedValue);
                break;

            case "Header":
                Headers.Add(name, adaptedValue);
                break;

            case "Query":
                Query.Add(name, adaptedValue);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type);
            }
            return(this);
        }
Beispiel #2
0
        private async Task <bool> Login(Proxy proxy, string username, string password)
        {
            using (WebSession session = new WebSession(proxy)) {
                RequestResponse rr = session.DispatchRequest(new GetRequest("https://www.pornhub.com/login"));

                if (!rr.Validate())
                {
                    Debug.WriteLine("Failed to load login page");
                    return(false);
                }
                Element tokenEl = rr.GetAsDoc().Select("[name=token]").First();

                if (tokenEl is null)
                {
                    Debug.WriteLine("Token not found");
                    return(false);
                }
                string token = tokenEl.Val;

                FormBody fb = new FormBody();
                fb.Add("loginPage", 1);
                fb.Add("redirect", "");
                fb.Add("token", token);
                fb.Add("taste_profile", "");
                fb.Add("username", username);
                fb.Add("password", password);
                fb.Add("remember_me", "on");

                rr = session.DispatchRequest(new PostRequest("https://www.pornhub.com/front/authenticate", fb));

                if (!rr.Validate())
                {
                    if (rr.ResponseCode == 500)
                    {
                        Debug.WriteLine("Blocked connection");
                        return(false);
                    }
                    Debug.WriteLine("Failed to login");
                    return(false);
                }
                Debug.WriteLine(rr.GetResponseContent());
                return(true);
            }
        }