http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 4419|回复: 4

[HttpHelper] 获取不到图片,我的代码肯定有错,但自己就是看不出来

[复制链接]
发表于 2014-10-12 08:46:13 | 显示全部楼层 |阅读模式
1金钱
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using DotNet4.Utilities;


namespace 请求新浪注册页
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "https://login.sina.com.cn/signup/signup?entry=blog",//URL     必需项
                Encoding =Encoding.GetEncoding("gb2312"),//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                Method = "Get",//URL     可选项 默认为Get
                UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0E; .NET4.0C)",//用户的浏览器类型,版本,操作系统     可选项有默认值
                Accept = "application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*",//    可选项有默认值
                Allowautoredirect = true
            };
            item.Header.Add("Accept-Language", "zh-CN");
            item.Header.Add("Accept-Encoding", "gzip, deflate");
            item.Host = "login.sina.com.cn";
            HttpResult result = http.GetHtml(item);
            richTextBox1.Text = result.Html;
            string picurl="https://login.sina.com.cn/cgi/pin.php?r="+ConvertDateTimeInt(DateTime.Now)+"&lang=zh&type=hollow";//URL     必需项
            
            HttpHelper http2 = new HttpHelper();
            HttpItem item2 = new HttpItem()
            {
                URL = picurl,
                Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                Method = "Get",//URL     可选项 默认为Get
                Cookie = result.Cookie,
                UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0E; .NET4.0C)",//用户的浏览器类型,版本,操作系统     可选项有默认值
                Accept = "*/*",//    可选项有默认值
                Referer = "https://login.sina.com.cn/signup/signup?entry=blog",//来源URL     可选项
                Allowautoredirect = true
            };
            item2.Host = "login.sina.com.cn";
            item2.Header.Add("Accept-Language", "zh-CN");
            item2.Header.Add("Accept-Encoding", "gzip, deflate");
            HttpResult result2 = http2.GetHtml(item2);
            pictureBox1.Image = byteArrayToImage(result2.ResultByte);


        }
        private Image byteArrayToImage(byte[] Bytes)
        {
            MemoryStream ms = new MemoryStream(Bytes);
            Image outputImg = Image.FromStream(ms);
            return outputImg;
        }
        public static long ConvertDateTimeInt(System.DateTime time)
        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
            long t = (time.Ticks - startTime.Ticks) / 10000;            //除10000调整为13位
            return t;
        }
    }
}


报错63、69行,意思就是提示result2.ResultByte为null,肯定是我写的代码不对,自己检查了好几遍,但是就是找不出自己的代码错在哪里了,麻烦大家帮忙了

最佳答案

查看完整内容

resulttype=resulttype.byte, 要加上这句的,指明返回的是byte[]。


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-10-12 08:46:14 | 显示全部楼层
resulttype=resulttype.byte,
要加上这句的,指明返回的是byte[]。
回复

使用道具 举报

发表于 2014-10-12 09:07:13 | 显示全部楼层
cload 发表于 2014-10-12 09:00
resulttype=resulttype.byte,
要加上这句的,指明返回的是byte[]。

正解~
回复

使用道具 举报

发表于 2014-10-12 09:28:51 | 显示全部楼层
ResultType = ResultType.Byte,//返回数据类型,是Byte还是String  
回复

使用道具 举报

 楼主| 发表于 2014-10-12 13:29:27 | 显示全部楼层
楼上诸位,多谢了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-2 06:26

© 2014-2021

快速回复 返回顶部 返回列表