[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,肯定是我写的代码不对,自己检查了好几遍,但是就是找不出自己的代码错在哪里了,麻烦大家帮忙了
|