参考例子:
byte[] image = File.ReadAllBytes(Environment.CurrentDirectory + @"\AnswerCode.gif");
var param = new Dictionary<object, object>
{ {"username","test123"}, {"password","123456"}, {"typeid","3040"}, {"timeout","90"}
};
string _tempcodehtml = "";
_tempcodehtml = httph.PostImage(urlcode, param, image);
Http获取图片,既可以通过链接地址,直接用Image的Location=URL也可以将图片流获取到本地,这样请求可以得到图片的Cookie,以便有些验证码存储在Cookie中,可以模拟验证码。
public Bitmap GetImage(string url, ref CookieContainer cookie, string refer)
{
HttpWebRequest hrq = (HttpWebRequest)WebRequest.Create(url);
hrq.Method = "GET";
try
{
HttpWebResponse hrp = (HttpWebResponse)hrq.GetResponse();
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(hrp.GetResponseStream());
if (cookie == null)
{
cookie.GetCookies(hrq.RequestUri);
}
hrp.Close();
return bmp;
}
catch (Exception)
{
return null;
}
}