public static string PostData(NameValueCollection postvars, string url)
{
//echo scripts which just print out the POST vars, handy for early stages of testing:
//const string url = "http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi";
//const string url = "http://www.tipjar.com/cgi-bin/test";
if (Globals.UnitTestMode) throw new Exception("You shouldn't access Wikipedia from unit tests");
HttpWebRequest rq = Variables.PrepareWebRequest(url);
rq.Method = "POST";
rq.ContentType = "application/x-www-form-urlencoded";
Stream requestStream = rq.GetRequestStream();
byte[] data = Encoding.UTF8.GetBytes(BuildPostDataString(postvars));
requestStream.Write(data, 0, data.Length);
requestStream.Close();
HttpWebResponse rs = (HttpWebResponse)rq.GetResponse();
if (rs.StatusCode == HttpStatusCode.OK)
return new StreamReader(rs.GetResponseStream()).ReadToEnd();
throw new WebException(rs.StatusDescription, WebExceptionStatus.UnknownError);
}