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 ...
随机推荐
- vs 2013 常用快捷键及常见问题的解决
1. 代码编辑 关闭当前文档:ctrl + F4 打开光标所在位置的文档:ctrl + G(shift + g) 返回上次编辑的位置:ctrl + -(键盘数字键 0 后的那个按键) 移动光标所在的行 ...
- Django之模板过滤器
Django 模板过滤器也是我们在以后基于 Django 网站开发过程中会经常遇到的,如显示格式的转换.判断处理等.以下是 Django 过滤器列表,希望对为大家的开发带来一些方便. 一.形式:小写 ...
- 诊断并解决CentOS SSH连接慢的方法
诊断并解决CentOS SSH连接慢的方法: http://os.51cto.com/art/201507/484743.htm
- Ambari——大数据平台的搭建利器(一)
Ambari 跟 Hadoop 等开源软件一样,也是 Apache Software Foundation 中的一个项目,并且是**项目.目前最新的发布版本是 2.0.1,未来不久将发布 2.1 版本 ...
- [HTML5] Using the tabindex attribute for keyboard accessibility
You can make any element keyboard interactive with the HTML tabindex attribute. But you might need a ...
- TensorFlow 实战(五)—— 图像预处理
当然 tensorflow 并不是一种用于图像处理的框架,这里图像处理仅仅是一些简单的像素级操作,最终目的比如用于数据增强: tf.random_crop() tf.image.random_flip ...
- ssh远程无法连接VM中的Ubuntu问题
Ubuntu ssh远程无法连接问题 1. 检查sudo ps -e|grep ssh 查看是否有ssh进程服务,如果没有的话,需要下载安装 sudo apt-get install openss ...
- error: invalid abbreviation code [25] for DIE at 0x0000003e in Assertion failed: (*offset_ptr == end_prologue_offset), function ParsePrologue, file /S
error: invalid abbreviation code [25] for DIE at 0x0000003e in '/Users/mac/Desktop/MYiosfiles/test/X ...
- 使用OTP原则构建一个非阻塞的TCP服务器
http://erlangcentral.org/wiki/index.php/Building_a_Non-blocking_TCP_server_using_OTP_principles CONT ...
- NOIP 模拟 玩积木 - 迭代加深搜索 / bfs+hash+玄学剪枝
题目大意: 有一堆积木,0号节点每次可以和其上方,下方,左上,右下的其中一个交换,问至少需要多少次达到目标状态,若步数超过20,输出too difficult 目标状态: 0 1 1 2 2 2 3 ...