Exemple #1
0
        /// <summary>
        /// Post запрос из формы.
        /// </summary>
        /// <param name="form">Форма.</param>
        /// <param name="host">Хост.</param>
        /// <param name="port">Порт.</param>
        /// <param name="proxyLogin">Логин прокси-сервера</param>
        /// <param name="proxyPassword">Пароль прокси-сервера</param>
        /// <returns>Результат</returns>
        public static WebCallResult Post(WebForm form, string host = null, int?port = null, string proxyLogin = null, string proxyPassword = null)
        {
            var call = new WebCall(form.ActionUrl, form.Cookies, host, port, proxyLogin, proxyPassword);

            var request = call.Request;

            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            var formRequest = form.GetRequest();

            request.ContentLength = formRequest.Length;
            request.Referer       = form.OriginalUrl;
            request.GetRequestStream().Write(formRequest, 0, formRequest.Length);
            request.AllowAutoRedirect = false;

            return(call.MakeRequest(host, port, proxyLogin, proxyPassword));
        }
Exemple #2
0
        /// <summary>
        /// Выполнить POST запрос.
        /// </summary>
        /// <param name="url">URL.</param>
        /// <param name="parameters">Параметры запроса.</param>
        /// <param name="host">Хост.</param>
        /// <param name="port">Порт.</param>
        /// <param name="proxyLogin">Логин прокси-сервера</param>
        /// <param name="proxyPassword">Пароль прокси-сервера</param>
        /// <returns>Результат</returns>
        public static WebCallResult PostCall(string url, string parameters, string host = null, int?port = null, string proxyLogin = null, string proxyPassword = null)
        {
            var call = new WebCall(url, new Cookies(), host, port, proxyLogin, proxyPassword)
            {
                Request =
                {
                    Method      = "POST",
                    ContentType = "application/x-www-form-urlencoded"
                }
            };

            var data = Encoding.UTF8.GetBytes(parameters);

            call.Request.ContentLength = data.Length;

            using (var requestStream = call.Request.GetRequestStream())
                requestStream.Write(data, 0, data.Length);

            return(call.MakeRequest(host, port, proxyLogin, proxyPassword));
        }
Exemple #3
0
        /// <summary>
        /// Выполнить запрос.
        /// </summary>
        /// <param name="url">URL.</param>
        /// <param name="host">Хост.</param>
        /// <param name="port">Порт.</param>
        /// <param name="proxyLogin">Логин прокси-сервера</param>
        /// <param name="proxyPassword">Пароль прокси-сервера</param>
        /// <returns>Результат</returns>
        public static WebCallResult MakeCall(string url, string host = null, int?port = null, string proxyLogin = null, string proxyPassword = null)
        {
            var call = new WebCall(url, new Cookies(), host, port, proxyLogin, proxyPassword);

            return(call.MakeRequest(host, port, proxyLogin, proxyPassword));
        }