/// <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 IDictionary <string, string> GetParameterList(WebForm form) { 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); } return(paramList); }
/// <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); } }