using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WebExam
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
WebRequest request = WebRequest.Create("http://www.163.com");
//request.BeginGetResponse(new AsyncCallback(OnResponse), request);异步页面请求
NetworkCredential cred = new NetworkCredential("admin", "admin");
//request.Credentials = cred;//验证
//WebProxy wp = new WebProxy("192.168.1.100", true);//代理
//wp.Credentials = cred;
HttpWebRequest httpRequest = (HttpWebRequest)request;
listBox1.Items.Add("Request time out(ms):" + request.Timeout);
listBox1.Items.Add("Request keep alive:" + httpRequest.KeepAlive);
listBox1.Items.Add("Request AllowAutoRedirect:" + httpRequest.AllowAutoRedirect);
WebResponse response = request.GetResponse();
WebHeaderCollection headers = response.Headers;
for (int i = 0; i < headers.Count; i++)
{
listBox1.Items.Add(string.Format("{0}:{1}",headers.GetKey(i),headers[i]));
}
}
//异步页面请求
//private void OnResponse(IAsyncResult ar)
//{
// WebRequest request = (WebRequest)ar.AsyncState;
// WebResponse response = request.EndGetResponse(ar);
// //read response
//}
}
}