/// <summary> /// creates a HttpPostDataCollection instance from a POST data string /// </summary> /// <param name="postdata"> /// the POST data string /// </param> /// <returns> /// a HttpPostDataCollection instance from the given POST data string /// </returns> public static HttpPostDataCollection FromString(string postdata) { HttpPostDataCollection col = new HttpPostDataCollection(); string[] pds = postdata.Split('&'); foreach (string[] pdkvp in pds.Select(pd => pd.Split('='))) { if (pdkvp.Length != 2) { throw new ArgumentException("malformed postdata", "postdata"); } col.Add(new HttpPostData(pdkvp[0], pdkvp[1])); } return(col); }
/// <summary> /// sends a HTTP POST request to a given URL with given POST data and a optional referer /// </summary> /// <typeparam name="TRespType"> /// return type of the Post request /// </typeparam> /// <param name="url"> /// the URL to send the post request to /// </param> /// <param name="postdata"> /// the POST data /// </param> /// <param name="referer"> /// the referer to send the request from /// </param> /// <returns> /// the response as TRespType /// </returns> public TRespType Post <TRespType>(string url, HttpPostDataCollection postdata, string referer = null) where TRespType : class { return(this.Post <TRespType>(url, postdata.ToString(), referer)); }