public HttpRequest(Cliver.Bot.HtmlForm html_form, Dictionary<string, string> headers = null)
 {
     if (headers != null)
         foreach (KeyValuePair<string, string> h in headers)
             Headers[h.Key] = h.Value;
     Url = html_form.Url;
     string query = "";
     foreach (string parameter in html_form.Names)
     {
         if (html_form.GetType(parameter) == HtmlForm.ParameterType.RESET)
             continue;
         foreach (string value in html_form[parameter])
             query += "&" + HttpUtility.UrlEncode(parameter) + "=" + HttpUtility.UrlEncode(value);
     }
     Method = html_form.Method;
     if (Method == RequestMethod.POST)
     {
         post_string = query;
         PostData = Encoding.UTF8.GetBytes(post_string);
         Headers["Content-Type"] = "application/x-www-form-urlencoded";
     }
     else
     {
         if (Url.Contains("?"))
             Url += query;
         else
             Url += "?" + query.Substring(1);
     }
 }
 public HttpRequest(string url, Dictionary<string, string> headers = null, HttpRequest.RequestMethod method = RequestMethod.GET, byte[] post_data = null)
 {
     Url = url;
     Method = method;
     if (post_data != null)
     {
         if (method != RequestMethod.POST) throw new Exception("RequestMethod is not POST while post_data is defined.");
         PostData = post_data;
     }
     if (headers != null)
         foreach(KeyValuePair<string,string> h in headers)
             Headers[h.Key] = h.Value;
 }
Example #3
0
 public HttpRequest(string url, Dictionary <string, string> headers = null, HttpRequest.RequestMethod method = RequestMethod.GET, byte[] post_data = null)
 {
     Url    = url;
     Method = method;
     if (post_data != null)
     {
         if (method != RequestMethod.POST)
         {
             throw new Exception("RequestMethod is not POST while post_data is defined.");
         }
         PostData = post_data;
     }
     if (headers != null)
     {
         foreach (KeyValuePair <string, string> h in headers)
         {
             Headers[h.Key] = h.Value;
         }
     }
 }