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. 基于bootstrap的富文本框——wangEditor【欢迎增加开发】

    先来一张效果图: 01. 引言 老早就開始研究富文本框的东西,在写完<深入理解javascript原型与闭包>之后,就想着要去做一个富文本框的插件的样例. 如今网络上开源的富文本框插件许多 ...

  2. CentOS-7-x86_64-DVD-1511.iso

    http://vault.centos.org/7.2.1511/isos/x86_64/CentOS-7-x86_64-DVD-1511.iso

  3. [Vue] Create Filters in Vue.js

    Just like in the command line, you can pipe a property through a filter to get a desired result. You ...

  4. mui列表跳转到详情页优化方案

    原理 因为列表页到详情页是多对一的形式,即列表页的多条数据列表对应的是一个详情页,只是数据不同而:因此,可以在加载列表页时预加载详情页,即创建一个详情页的webview,但是不显示出来,点击列表的时候 ...

  5. java 替换json字符串中间的引号保留两边的引号,避免json校验失败

    一.json概要 JSON(JavaScript Object Notation, JS 对象标记)-一种轻量级的数据交换标准(相对xml),独立于编程语言.具体以逗号分隔的key:value键值对的 ...

  6. 呈现样式UIModalPresentation

    nModal   n在iPhone开发中 pModal是一种常见的切换控制器的方式 p默认是从屏幕底部往上弹出,直到完全盖住后面的内容为止 n n在iPad开发中 pModal的使用频率也是非常高的 ...

  7. 对Java JVM中类加载几点解释

    1.用到类的时候,类加载到方法区,同时方法区会存放static的内容(包括静态方法和静态变量),随类的加载而加载 2当new的时候,会在堆中创建一个对象,在其中会开辟其中的实例变量内存并初始化,堆中变 ...

  8. 【56.74%】【codeforces 732B】Cormen --- The Best Friend Of a Man

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【20.69%】【codeforces 732E】Sockets

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  10. 《深入浅出WPF》笔记——资源篇

    原文:<深入浅出WPF>笔记--资源篇 前面的记录有的地方已经用到了资源,本文就来详细的记录一下WPF中的资源.我们平时的“资源”一词是指“资财之源”,是创造人类社会财富的源泉.在计算机程 ...