C# WebRequest WebResponse的使用
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的使用的更多相关文章
- httpwebrequest webrequest webresponse 总结
http://blog.csdn.net/flymorn/article/details/6769722 使用,总结,深入,全通,指正
- C#:使用WebRequest类请求数据
本文翻译于:https://msdn.microsoft.com/en-us/library/456dfw4f(v=vs.110).aspx 下列程序描述的步骤用于从服务器请求一个资源,例如,一个We ...
- 一步一步学Silverlight 2系列(13):数据与通信之WebRequest
概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...
- C# 调用webservice 几种办法(转载)
原文地址: http://www.cnblogs.com/eagle1986/archive/2012/09/03/2669699.html //=========================== ...
- 调用webservice 总结
最近做一个项目,由于是在别人框架里开发app,导致了很多限制,其中一个就是不能直接引用webservice . 我们都知道,调用webserivice 最简单的方法就是在 "引用" ...
- C#动态webservice调用接口 (JAVA,C#)
C#动态webservice调用接口 using System; using System.Collections; using System.IO; using System.Net; using ...
- silverlight: http请求的GET及POST示例
http请求的get/post并不是难事,只是silverlight中一切皆是异步,所以代码看起来就显得有些冗长了,下面这个HttpHelper是在总结 园友 的基础上,修改得来: namespace ...
- Webservice学习
参考博客1: http://www.cnblogs.com/lzhp/archive/2013/01/13/2858559.html 参考博客2:http://blog.csdn.net/shilei ...
- WebServiceCaller
WebServiceCaller /* jonney 2015-09-19 */ using System; using System.Collections; using System.Collec ...
随机推荐
- ssion机制详解
ssion机制详解 ref:http://justsee.iteye.com/blog/1570652 虽然session机制在web应用程序中被采用已经很长时间了,但是仍然有很多人不清楚sess ...
- Unity3d优化包的大小
http://wenku.baidu.com/link?url=MEUtNP6k1W7gXK2LcHdKXGqwoTD4HZDsBpsu9iFYjuL3WCIXgl2-rBHhBWP_zo5Xm4Yx ...
- Android中的动画详解系列【1】——逐帧动画
逐帧动画其实很简单,下面我们来看一个例子: <?xml version="1.0" encoding="utf-8"?> <animation ...
- Smarty3.1.8 安装
应用环境:Winsows7 IIS + PHP5.5.12 + Smarty3.1.8 1. IIS 及 PHP 安装,参照<php手册>,这里不做细表. 2. 假定应用目录为 C:\in ...
- Display controller
Field of the Invention The present invention relates to a display controller. Background to the inve ...
- CentOS下Apache的停止和卸载
昨晚搞到一台全球性价比最高的服务器,折腾一晚上,好不容易把node服务开启了,结果访问不了我的网站!!! 访问我的网站,显示的是一个Apache欢迎页面.我想,是不是像之前那样,80端口没有开放,然后 ...
- Android Studio 报错Guest isn't online after 7 seconds 解决方案
最近使用真机模拟之后,再使用虚拟机就频繁出现这个问题; 解决步骤如下: 1.打开Android虚拟设备管理器, 2.查看Actoins栏下拉图标, 3.选择冷启动模式即可, 4.重启AVD正常;
- handsontable前端excel学习笔记
暂时没有好的中文资料,大概找了三遍随便看看,之后重点研究其github 1.Handsontable 学习笔记-Methods 2. Handsontable通用方法 3.handsontable的核 ...
- droid开发中监听器的三种实现方法(OnClickListener)
Android开发中监听器的实现有三种方法,对于初学者来说,能够很好地理解这三种方法,将能更好地增进自己对android中监听器的理解. 一.什么是监听器. 监听器是一个存在于View类下的接口,一般 ...
- GammaRay is a tool to poke around in a Qt-application(确实很多功能)
GammaRay is a tool to poke around in a Qt-application and also to manipulate the application to some ...