public static MyHttpWebRequest Create(string url)
        {
            var httpWebRequest   = (HttpWebRequest)WebRequest.Create(url);
            var myHttpWebRequest = new MyHttpWebRequest()
            {
                httpWebRequest = httpWebRequest
            };

            return(myHttpWebRequest);
        }
Пример #2
0
        public MyHttpWebResponse SubmitForm(string submitInputName = null)
        {
            if (submitInputName.IsNullOrEmpty() == false)
            {
                submitInputName = GlobSearch(submitInputName, submitInputs);
                FillInput(submitInputName, submitInputs[submitInputName]);
            }

            var url = formHtmlElement.GetAttributeValue("action", "?");

            if (url.StartsWith("/") == false && url.StartsWith(@"\") == false)
            {
                url = "/" + url;
            }
            url = rootFormUrl + url;

            var method = formHtmlElement.GetAttributeValue("method", "post").Trim().ToLower();

            if (method == "get")
            {
                url += "?" + paramsCollection.ToData();
            }

            var request = MyHttpWebRequest.Create(url);

            request.CookieContainer = cookieContainer;
            request.Method          = method;
            request.ContentType     = "application/x-www-form-urlencoded";

            if (method == "post")
            {
                var s = request.GetRequestStream();
                using (var t = new StreamWriter(s))
                {
                    t.Write(paramsCollection.ToData());
                }
            }
            if (method == "get")
            {
                request.ContentLength = 0;
            }

            var response = request.GetResponse();

            return(response);
        }