Esempio n. 1
0
 public string POST(string url = null, string POSTData = null, HttpWebRequest req = null)
 {
     if (req == null)
     {
         req = (HttpWebRequest)HttpWebRequest.Create(url);
     }
     req.Method      = "POST";
     req.ContentType = "application/x-www-form-urlencoded";
     AddHeaders(ref req);
     if (POSTData != null)
     {
         byte[] buf = Encoding.Default.GetBytes(POSTData);
         req.ContentLength = buf.Length;
         req.GetRequestStream().Write(buf, 0, buf.Length);
     }
     try {
         var resp = req.GetResponse();
         Cookies.ParseCollection(resp.Headers);
         var code = ((HttpWebResponse)resp).StatusCode;
         return(new StreamReader(resp.GetResponseStream()).ReadToEnd());
     } catch (Exception e) {
         Console.WriteLine(e.ToString());
     }
     //Console.WriteLine("fail");
     return("fail");
 }