【发布时间】:2012-02-29 22:13:23
【问题描述】:
我正在为一家公司创建一个应用程序,该应用程序将在 windows 应用程序中填写表格,并且将向服务器发送一个发布请求以注册用户。
为了发送 POST 请求,我使用了 curl
private void post_data(string url, string data)
{
Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
Easy e = new Easy();
Easy.WriteFunction wf = MyWriteFunction;
e.SetOpt(CURLoption.CURLOPT_URL, url);
e.SetOpt(CURLoption.CURLOPT_POSTFIELDS, data);
e.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
e.Perform();
e.Cleanup();
}
private int MyWriteFunction(byte[] buf, int size, int nmemb, Object extraData)
{
StreamWriter sw = new StreamWriter(@"curl.txt");
foreach (byte b in buf)
{
sw.Write(((char)b));
}
sw.Flush();
sw.Close();
return buf.Length;
}
为了从源代码中提取验证码图片路径,让用户输入文字
private void Get_Captcha_Image(string url)
{
Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
Easy e = new Easy();
Easy.WriteFunction wf = MyWriteFunction;
e.SetOpt(CURLoption.CURLOPT_URL, url);
e.SetOpt(CURLoption.CURLOPT_WRITEFUNCTION, wf);
e.Perform();
e.Cleanup();
get_ca_2();
}
private void get_ca_2()
{
Regex r = new Regex(@"(?<=src=('|""))https?://.*?(?=\1)");
foreach (string line in File.ReadAllLines("curl.txt"))
{
Match m = r.Match(line);
if (m.Success)
{
if (m.Value.Contains("http://www.google.com/recaptcha/api/image?c="))
{
pictureBox1.ImageLocation = m.Value;
}
}
}
}
但我注意到的是
<img width="300" height="57" src="http://www.google.com/recaptcha/api/image?c=03AHJ_VuvnenuZSRbfL_JTQLTYKFYzEFTkYrDgedu0SLyYvTDhsr2hHjQPwYlGJiP3dJRewkIhhdeILAd1_61_aFfU2dclbf8uovme-0gF3nm8Y7-LQVfaDQoI35bo3c35pOnF-xSY3Qfy_lh8TzhSWlMemEnkYnDpZw" alt="reCAPTCHA challenge image" style="display:block;">
例如在使用 curl 提取的网页源代码中不存在
我厌倦了网络浏览器并将其隐藏,我能够找到验证码图像,并且我成功发布了数据,但我需要在 curl 上找到它
【问题讨论】:
标签: c# regex curl http-post libcurl