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. Shuttle ESB(三)——架构模型介绍(2)

    上一篇文章中,介绍了Shuttle ESB架构模型中的三个重要部分. 今天,我们继续介绍剩余的三个内容:模式和消息路由. 四.模式 Request/Response(请求/响应模式) 对基于Reque ...

  2. thinkphp中ajax使用实例(thinkphp内置支持ajax)

    thinkphp中ajax使用实例(thinkphp内置支持ajax) 一.总结 1.thinkphp应该是内置支持ajax的,所以请求类型里面才会有是否是ajax // 是否为 Ajax 请求 if ...

  3. nas docker xunlei

    http://bbs.xunlei.com/thread-389018-1-1.html 首先,启动远程服务,找到你的设备IP,在浏览器里输入以下地址,host换成你设备的IP http://host ...

  4. Warning: preg_replace(): Compilation failed: missing terminating ] for character class at offset 10 in

    Warning: preg_replace(): Compilation failed: missing terminating ] for character class at offset 10 ...

  5. 代码中jndi数据源的支持

    项目中基本都使用Spring框架,支持jndi还是很简单的,只需在spring配置文件中加入 <!-- 使用jndi配置数据源 --> <bean id="dataSour ...

  6. 流媒体协议介绍(rtp/rtcp/rtsp/rtmp/mms/hls

    http://blog.csdn.net/tttyd/article/details/12032357 RTP           参考文档 RFC3550/RFC3551 Real-time Tra ...

  7. NOIP模拟 乘积 - 状压dp + 分组背包

    题目大意: 给出n和k,求从小于等于n的数中取出不超过k个,其乘积是无平方因子数的方案数.无平方因子数:不能被质数的平方整除. 题目分析: 10(枚举\(n\le8\)),40(简单状压\(n\le1 ...

  8. HDU 1080 Human Gene Functions - 最长公共子序列(变形)

    传送门 题目大意: 将两个字符串对齐(只包含ACGT,可以用'-'占位),按照对齐分数表(参见题目)来计算最后的分数之和,输出最大的和. 例如:AGTGATG 和 GTTAG ,对齐后就是(为了表达对 ...

  9. padding百分百值是相对谁的百分比

    先看代码 <head> <meta charset="UTF-8"> <title>Document</title> <sty ...

  10. Java获取URL对应的资源

    Java获取URL对应的资源   认识IP.认识URL是进行网络编程的第一步.java.net.URL提供了丰富的URL构建方式,并可以通过java.net.URL来获取资源.   一.认识URL   ...