public string PostCaptchaToAntigate(Bitmap bitmap, string url, string captchaKey, string additionalParams="CapMonsterModule=ZennoLab.ReCaptcha2&Task=\"cars\"")
{
string res = "Error";
var myReq = (HttpWebRequest)WebRequest.Create(string.Format("http://{0}/in.php", url));
myReq.UserAgent = "TubeCast v1.0";
myReq.Accept = "*/*";
myReq.Headers.Add("Accept-Language", "ru");
myReq.Host = "antigate.com";
myReq.KeepAlive = true;
myReq.AllowAutoRedirect = false;
myReq.Method = "POST";
string sBoundary = DateTime.Now.Ticks.ToString("x");
myReq.ContentType = "multipart/form-data; boundary=" + sBoundary;
string sPostMultiString = "";
sPostMultiString += MultiFormData("method", "post", sBoundary);
sPostMultiString += MultiFormData("soft_id", "0", sBoundary);
sPostMultiString += MultiFormData("key", captchaKey, sBoundary);
try
{
var pear = additionalParams.Split('&');
foreach (string str in pear)
{
var pV = str.Split('=');
if (pV.Length >= 2) sPostMultiString += MultiFormData(pV[0], pV[1], sBoundary);
}
}
catch
{
}
var bitmapByte = ToArray(bitmap, ImageFormat.Png);
string sFileContent = Encoding.GetEncoding(1251).GetString(bitmapByte);
sPostMultiString += MultiFormDataFile("file", sFileContent, "Collection.png", "image/png", sBoundary);
sPostMultiString += "--" + sBoundary + "--\r\n\r\n";
var byteArray = Encoding.GetEncoding(1251).GetBytes(sPostMultiString);
myReq.ContentLength = byteArray.Length;
try
{
myReq.GetRequestStream().Write(byteArray, 0, byteArray.Length);
var ret = (HttpWebResponse)myReq.GetResponse();
var reader = new StreamReader(ret.GetResponseStream(), Encoding.GetEncoding(1251));
var pg = reader.ReadToEnd();
var pars = pg.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
res = pars.Length > 1 ? pars[1] : pg;
return res;
}
catch (Exception ex)
{
}
return res;
}
private string MultiFormData(string key, string value, string boundary)
{
var output = string.Format("--{0}\r\n", boundary);
output += string.Format("Content-Disposition: form-data; name=\"{0}\"\r\n\r\n", key);
output += value + "\r\n";
return output;
}
private string MultiFormDataFile(string key, string value, string fileName, string fileType, string boundary)
{
var output = string.Format("--{0}\r\n", boundary);
output += string.Format("Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n", key, fileName);
output += string.Format("Content-Type: {0} \r\n\r\n", fileType);
output += string.Format("{0}\r\n", value);
return output;
}
private byte[] ToArray(Bitmap image, ImageFormat format)
{
byte[] bytes;
using (var ms = new MemoryStream())
{
image.Save(ms, format);
bytes = ms.ToArray();
}
return bytes;
}