Пример #1
0
        /// <summary>
        /// Post запрос из формы.
        /// </summary>
        /// <param name="form"> Форма. </param>
        /// <param name="webProxy"> Хост. </param>
        /// <returns> Результат </returns>
        public static WebCallResult Post(WebForm form, IWebProxy webProxy)
        {
                #if DEBUG_HTTP
            LogWebCallRequestInfo("POST", form.ActionUrl, form.GetFormFields(), webProxy);
            var watch = System.Diagnostics.Stopwatch.StartNew();
                        #endif

            using (var call = new WebCall(url: form.ActionUrl, cookies: form.Cookies, webProxy: webProxy, allowAutoRedirect: false))
            {
                SpecifyHeadersForFormRequest(form: form, call: call);

                var response = call._request
                               .PostAsync(requestUri: form.ActionUrl, content: new FormUrlEncodedContent(nameValueCollection: form.GetFormFields()))
                               .Result;

                var res = call.MakeRequest(response: response, uri: new Uri(uriString: form.ActionUrl), webProxy: webProxy);

                        #if DEBUG_HTTP
                watch.Stop();
                LogWebCallResultDebugInfo("POST", form.ActionUrl, response, res, watch.ElapsedMilliseconds);
                                #endif

                return(res);
            }
        }
Пример #2
0
        /// <summary>
        /// Post запрос из формы асинхронно.
        /// </summary>
        /// <param name="form"> Форма. </param>
        /// <param name="webProxy"> Хост. </param>
        /// <returns> Результат </returns>
        public static async Task <WebCallResult> PostAsync(WebForm form, IWebProxy webProxy)
        {
            using (var call = new WebCall(url: form.ActionUrl, cookies: form.Cookies, webProxy: webProxy, allowAutoRedirect: false))
            {
                SpecifyHeadersForFormRequest(form: form, call: call);

                var request = await call._request.PostAsync(requestUri : form.ActionUrl
                                                            , content : new FormUrlEncodedContent(nameValueCollection: form.GetFormFields()));

                return(await call.MakeRequestAsync(response : request, uri : new Uri(uriString: form.ActionUrl), webProxy : webProxy));
            }
        }
Пример #3
0
        /// <summary>
        /// Post запрос из формы асинхронно.
        /// </summary>
        /// <param name="form">Форма.</param>
        /// <param name="webProxy">Хост.</param>
        /// <returns>Результат</returns>
        public static async Task <WebCallResult> PostAsync(WebForm form, IWebProxy webProxy)
        {
            using (var call = new WebCall(form.ActionUrl, form.Cookies, webProxy, false))
            {
                SpecifyHeadersForFormRequest(form, call);

                var request = await call._request.PostAsync(form.ActionUrl, new FormUrlEncodedContent(form.GetFormFields()));

                return(await call.MakeRequestAsync(request, new Uri(form.ActionUrl), webProxy));
            }
        }