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

参考例子:

 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;
            }
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值