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. [Angular] Router outlet events

    For example, we have a component which just simply render router-outlet: import { Component } from ' ...

  2. Java的面向AOP编程

    一. 引言 AOP(Aspect-Oriented Programming,面向切面的编程),是一种新型的编程范式,主张关注软件流程中的一个切面,将相同功能的代码整合打包在一起,减少系统的耦合性,增强 ...

  3. [Compose] Isomorphisms and round trip data transformations

    What is Isomorphisms?We have a value x, then apply function 'to' and 'from' to value 'x', the result ...

  4. [Postgres] Update and Delete records in Postgres

    Delete example: DELETE FROM movies ; Update example: UPDATE movies ;

  5. Android 自定义View——自定义点击事件

    每个人手机上都有通讯录,这是毫无疑问的,我们通讯录上有一个控件,在通讯录的最左边有一列从”#”到”Z”的字母,我们通过滑动或点击指定的字母来确定联系人的位置,进而找到联系人.我们这一节就通过开发这个控 ...

  6. [Angular] Difference between Providers and ViewProviders

    For example we have a component: class TodoList { private todos: Todo[] = []; add(todo: Todo) {} rem ...

  7. Change Sudoers Mod 777 To 0440

    Method 1: > grub --> recovery mode --> e > ro single <--> rw single init=/bin/bash ...

  8. 生成式模型(generative) vs 判别式模型(discriminative)

    Andrew Ng, On Discriminative vs. Generative classifiers: A comparison of logistic regression and nai ...

  9. 设计模式在JDK中的应用

    在JDK(Java Development Kit)类库中,开发人员使用了大量设计模式. 创建型模式: (1) 抽象工厂模式(Abstract Factory) • java.util.Calenda ...

  10. APP和服务端-架构设计(二)

    1. App架构设计经验谈:接口的设计 App与服务器的通信接口如何设计得好,需要考虑的地方挺多的,在此根据我的一些经验做一些总结分享,旨在抛砖引玉. 1.1 安全机制的设计 现在,大部分App的接口 ...