Código
Y así es como llamo a la función:
public string Post(Uri wiki, string uri, string post_data, CookieCollection cookie = null) { try { // create a request HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri); request.KeepAlive = true; request.Headers.Add("Accept-Encoding", "gzip"); request.AutomaticDecompression = DecompressionMethods.GZip; //if cookies parameters not is false, send the cookies! if (cookie != null) { request.CookieContainer.Add(wiki, cookie); } request.ProtocolVersion = HttpVersion.Version10; request.Method = "POST"; //The fantastic user agent request.UserAgent = "inteliBOT/1.0 (https://es.wikipedia.org/wiki/Usuario:InteliBOT)"; System.Net.ServicePointManager.Expect100Continue = false; // turn our request string into a byte stream byte[] postBytes = Encoding.UTF8.GetBytes(post_data); // this is important - make sure you specify type this way request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postBytes.Length; Stream requestStream = request.GetRequestStream(); // now send it requestStream.Write(postBytes, 0, postBytes.Length); requestStream.Close(); // grab te response and print it out to the console along with the status code HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string respuesta = Reader.ReadToEnd(); return respuesta; } catch (Exception e) { Console.WriteLine(e.Message); MessageBoxButtons buttons = MessageBoxButtons.OK; string message = e.Message; string caption = "Error"; DialogResult dresult; dresult = MessageBox.Show(message, caption, buttons, MessageBoxIcon.Error); login.ActiveForm.Show(); loging.ActiveForm.Close(); return e.Message; }
Código
Gracias de antemano por sus respuestas
Cookies.Add(CookieSession); Cookies.Add(CookieToken); string result2 = Post(Url, wiki, String.Format("action=login&lgname={0}&lgpassword={1}&lgtoken={2}&format=xml", bot, pass, token), Cookies);