您的位置:首页 > 其它

继上一篇文章,由于本地限制,等后续整理在一起

2015-08-13 11:21 267 查看
参考例子:

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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: