/// <summary> /// Post запрос из формы. /// </summary> /// <param name="form">Форма.</param> /// <param name="webProxy">Хост.</param> /// <returns>Результат</returns> public static WebCallResult Post(WebForm form, IWebProxy webProxy) { using (var call = new WebCall(form.ActionUrl, form.Cookies, webProxy, false)) { var formRequest = form.GetRequest(); var headers = call._request.DefaultRequestHeaders; headers.Add("Method", "POST"); headers.Add("ContentType", "application/x-www-form-urlencoded"); headers.Add("ContentLength", formRequest.Length.ToString()); headers.Referrer = new Uri(form.OriginalUrl); var paramList = new Dictionary <string, string>(); foreach (var param in form.GetRequestAsStringArray()) { if (paramList.ContainsKey(param)) { continue; } var paramPair = param.Split('='); var key = paramPair[0] + ""; var value = paramPair[1] + ""; paramList.Add(key, value); } var request = call._request.PostAsync(form.ActionUrl, new FormUrlEncodedContent(paramList)).Result; return(call.MakeRequest(request, new Uri(form.ActionUrl), webProxy)); } }
private static void SpecifyHeadersForFormRequest(WebForm form, WebCall call) { var formRequest = form.GetRequest(); var headers = call._request.DefaultRequestHeaders; headers.Add("Method", "POST"); headers.Add("ContentType", "application/x-www-form-urlencoded"); headers.Add("ContentLength", formRequest.Length.ToString()); headers.Referrer = new Uri(form.OriginalUrl); }
public static WebCallResult Post(WebForm form) { var call = new WebCall(form.ActionUrl, form.Cookies); var request = call.Request; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; var formRequest = form.GetRequest(); request.ContentLength = formRequest.Length; request.GetRequestStream().Write(formRequest, 0, formRequest.Length); request.AllowAutoRedirect = false; request.Referer = form.OriginalUrl; return call.MakeRequest(); }
/// <summary> /// Post запрос из формы. /// </summary> /// <param name="form">Форма.</param> /// <param name="host">Хост.</param> /// <param name="port">Порт.</param> /// <returns>Результат</returns> public static WebCallResult Post(WebForm form, string host = null, int?port = null) { var call = new WebCall(form.ActionUrl, form.Cookies, host, port); 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)); }
/// <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); }
/// <summary> /// Post запрос из формы. /// </summary> /// <param name="form">Форма.</param> /// <param name="webProxy">Хост.</param> /// <returns>Результат</returns> public static WebCallResult Post(WebForm form, IWebProxy webProxy) { using (var call = new WebCall(form.ActionUrl, form.Cookies, webProxy, false)) { var formRequest = form.GetRequest(); var headers = call._request.DefaultRequestHeaders; headers.Add("Method", "POST"); headers.Add("ContentType", "application/x-www-form-urlencoded"); headers.Add("ContentLength", formRequest.Length.ToString()); headers.Referrer = new Uri(form.OriginalUrl); var paramList = new Dictionary<string, string>(); foreach (var param in form.GetRequestAsStringArray()) { if (paramList.ContainsKey(param)) { continue; } var paramPair = param.Split('='); var key = paramPair[0] + ""; var value = paramPair[1] + ""; paramList.Add(key, value); } var request = call._request.PostAsync(form.ActionUrl, new FormUrlEncodedContent(paramList)).Result; return call.MakeRequest(request, new Uri(form.ActionUrl), webProxy); } }