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
        //}
    }
}

C# WebRequest WebResponse的使用的更多相关文章

  1. httpwebrequest webrequest webresponse 总结

    http://blog.csdn.net/flymorn/article/details/6769722 使用,总结,深入,全通,指正

  2. C#:使用WebRequest类请求数据

    本文翻译于:https://msdn.microsoft.com/en-us/library/456dfw4f(v=vs.110).aspx 下列程序描述的步骤用于从服务器请求一个资源,例如,一个We ...

  3. 一步一步学Silverlight 2系列(13):数据与通信之WebRequest

    概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...

  4. C# 调用webservice 几种办法(转载)

    原文地址: http://www.cnblogs.com/eagle1986/archive/2012/09/03/2669699.html //=========================== ...

  5. 调用webservice 总结

    最近做一个项目,由于是在别人框架里开发app,导致了很多限制,其中一个就是不能直接引用webservice . 我们都知道,调用webserivice 最简单的方法就是在 "引用" ...

  6. C#动态webservice调用接口 (JAVA,C#)

    C#动态webservice调用接口 using System; using System.Collections; using System.IO; using System.Net; using ...

  7. silverlight: http请求的GET及POST示例

    http请求的get/post并不是难事,只是silverlight中一切皆是异步,所以代码看起来就显得有些冗长了,下面这个HttpHelper是在总结 园友 的基础上,修改得来: namespace ...

  8. Webservice学习

    参考博客1: http://www.cnblogs.com/lzhp/archive/2013/01/13/2858559.html 参考博客2:http://blog.csdn.net/shilei ...

  9. WebServiceCaller

    WebServiceCaller /* jonney 2015-09-19 */ using System; using System.Collections; using System.Collec ...

随机推荐

  1. JavaEE分层知识点粗略解释

    JavaEE知识点总结 什么是分层开发? 一种化大为小,分而治之的软件开发方法. 分层的特点: 1.每一层都有自己的责任. 2.上一层不用关心下一层的实现细节,上一层通过下一层 提供的对外接口来使用其 ...

  2. Qt 学习: 视图选择 (QItemSelectionModel)

    博主QQ:1356438802 选择是视图中经常使用的一个操作.在列表.树或者表格中,通过鼠标点击能够选中某一项,被选中项会变成高亮或者反色.在 Qt 中,选择也是使用了一种模型.在 model/vi ...

  3. Tokumx vs Mongodb

    Mongodb是一个文档型nosql数据库 採用C++编写 Mongo DB最大的优势在于全部的数据持久操作都无需开发者手动编写SQL语句,直接调用方法就能够轻松的实现CRUD操作. 非常多人觉得mo ...

  4. javaScript实现简单网页倒计时代码

    <div id="button"> <input type="button" value="同意" id="b0 ...

  5. NSNull 和 nil 的判断

    情况1. 等于Null if ([_content isEqual:[NSNull null]] ) { //等于Null } 情况2.  等于nil if (_content==nil || [_c ...

  6. 判断navigation中父控制器类型

    for (UIViewController *controller in self.navigationController.viewControllers) { if ([controller is ...

  7. Power aware dynamic scheduling in multiprocessor system employing voltage islands

    Minimizing the overall power conservation in a symmetric multiprocessor system disposed in a system- ...

  8. 常见的面试C#技术题目

    遍历查询窗体界面的textbox为空值 ? foreach (System.Windows.Forms.Control control in this.Controls)            {   ...

  9. 排序 —— 希尔排序(Shell sort)

    希尔排序(Shell sort)的名称源于它的发明者 Donald Shell,该算法是冲破二次时间屏障(冒泡和插入排序,基于相邻元素的交换)的第一批算法.希尔排序改进了冒泡和插入排序的相邻元素才进行 ...

  10. XCode5.1.1怎样实现代码块自己主动排版

    1.问题描写叙述 在开发中常常遇到代码块须要排版的情况,假设一行一行缩进就太out了,但在xcode中怎样实现还真不知道 2.解决方法 2.1选中须要排版的代码块 2.2单击"Editor ...