1. 总结

总结2

3. Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
using System.Web; namespace Core
{
public class RequestHelper
{
private Stream SendGetRequest1(string url)
{
string content;
//HttpRequest request;// Enables ASP.NET to read the HTTP values sent by a client during a Web request.
WebRequest webrequest;// Makes a request to a Uniform Resource Identifier (URI). This is an abstract
HttpWebRequest httpWebRequest;// Provides an HTTP-specific implementation of the System.Net.WebRequest class.
HttpWebResponse httpWebResponse;
//string url = "fsefsf";
httpWebRequest = WebRequest.Create(url) as HttpWebRequest;
httpWebRequest.AllowAutoRedirect = true;
httpWebRequest.Method = "GET";
httpWebRequest.ContentType = "application/x-www-form-urlencoded"; //httpwebrequest.ContentType = "application/json";
//httpwebrequest.ContentType = "application/xml";
//httpwebrequest.Headers.Add("url",url); httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
Stream resStream = httpWebResponse.GetResponseStream();
using (StreamReader sr = new StreamReader(resStream))
{
content = sr.ReadToEnd();
}
if (httpWebResponse.StatusCode != HttpStatusCode.OK)
{ }
return resStream;
}
private Stream SendGetRequestForStream(string url, string contentType)
{
HttpWebRequest httpWebRequest;// Provides an HTTP-specific implementation of the System.Net.WebRequest class.
HttpWebResponse httpWebResponse;
httpWebRequest = WebRequest.Create(url) as HttpWebRequest;
httpWebRequest.Method = "GET";
httpWebRequest.ContentType = contentType;
httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
Stream resStream = httpWebResponse.GetResponseStream();
return resStream;
} private String SendGetRequest(string url, string contentType)
{
string content = "";
HttpWebRequest httpWebRequest;
HttpWebResponse httpWebResponse;
httpWebRequest = WebRequest.Create(url) as HttpWebRequest;
httpWebRequest.Method = "GET";
httpWebRequest.ContentType = contentType;//"application/x-www-form-encoded";
httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
Stream resStream = httpWebResponse.GetResponseStream();
using (StreamReader sr = new StreamReader(resStream))
{
content = sr.ReadToEnd();
}
return content;
} private Stream SendPostRequestForStream(string url, string data, string contentType)
{
//string content = "";
HttpWebRequest httpWebRequest;
HttpWebResponse httpWebResponse;
httpWebRequest = WebRequest.Create(url) as HttpWebRequest;
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = contentType;
Stream reqStream = httpWebRequest.GetRequestStream();
using (StreamWriter sw = new StreamWriter(reqStream))
{
sw.Write(data);
}
httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
Stream ResStream = httpWebResponse.GetResponseStream(); return ResStream;
} private String SendPostRequest(string url, string data, string contentType)
{
string content = "";
HttpWebRequest httpWebRequest;
HttpWebResponse httpWebResponse;
httpWebRequest = WebRequest.Create(url) as HttpWebRequest;
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = contentType;
Stream reqStream = httpWebRequest.GetRequestStream();
using (StreamWriter sw = new StreamWriter(reqStream))
{
sw.Write(data);
}
httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
Stream resStream = httpWebResponse.GetResponseStream();
using (StreamReader sr = new StreamReader(resStream))
{
content = sr.ReadToEnd();
} return content;
}
}
}

HttpWebRequest 和HttpWebResponse总结的更多相关文章

  1. C# HttpWebRequest与HttpWebResponse详解

    C# HttpWebRequest与HttpWebResponse详解  http://www.codeproject.com/Articles/6554/How-to-use-HttpWebRequ ...

  2. 使用HttpWebRequest以及HttpWebResponse读取Http远程文件

     主页>杂项技术>.NET(C#)> 使用HttpWebRequest以及HttpWebResponse读取Http远程文件 jackyhwei 发布于 2010-08-15 21: ...

  3. HttpWebRequest和HttpWebResponse用法小结

    http://www.cnblogs.com/willpan/archive/2011/09/26/2176475.html http://www.cnblogs.com/lip0121/p/4539 ...

  4. 利用HttpWebRequest和HttpWebResponse获取Cookie

    之前看过某个同学的一篇有关与使用JSoup解析学校图书馆的文章,仔细一看,发现竟然是同校!!既然对方用的是java,那么我也就来个C#好了,虽然我的入门语言是java. C#没有JSoup这样方便的东 ...

  5. c# HttpWebRequest与HttpWebResponse 绝技(转载)

    c# HttpWebRequest与HttpWebResponse 绝技    如果你想做一些,抓取,或者是自动获取的功能,那么就跟我一起来学习一下Http请求吧.本文章会对Http请求时的Get和P ...

  6. C#模拟POST提交表单(二)--HttpWebRequest以及HttpWebResponse

    上次介绍了用WebClient的方式提交POST请求,这次,我继续来介绍用其它一种方式 HttpWebRequest以及HttpWebResponse 自认为与上次介绍的WebClient最大的不同之 ...

  7. C# 利用 HttpWebRequest 和 HttpWebResponse 模拟登录有验证码的网站

    原文:C# 利用 HttpWebRequest 和 HttpWebResponse 模拟登录有验证码的网站 我们经常会碰到需要程序模拟登录一个网站,那如果网站需要填写验证码的要怎样模拟登录呢?这篇文章 ...

  8. 利用HttpWebRequest和HttpWebResponse获取Cookie并实现模拟登录

    利用HttpWebRequest和HttpWebResponse获取Cookie并实现模拟登录 tring cookie = response.Headers.Get("Set-Cookie ...

  9. C# -- HttpWebRequest 和 HttpWebResponse 的使用

    C# -- HttpWebRequest 和 HttpWebResponse 的使用 结合使用HttpWebRequest 和 HttpWebResponse,来判断一个网页地址是否可以正常访问. 1 ...

  10. C#使用HttpWebRequest和HttpWebResponse上传文件示例

    C#使用HttpWebRequest和HttpWebResponse上传文件示例 1.HttpHelper类: 复制内容到剪贴板程序代码 using System;using System.Colle ...

随机推荐

  1. Maximal Rectangle [LeetCode]

    Problem Description: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle co ...

  2. 玩转linux文件(重点)

    一.几个主要的操作 mkdir—创建目录 cp—复制文件和目录 mv——移动/重命名文件和目录 rm——删除文件和目录 ln——创建硬链接和软链接 二.几个考点: 通配符 硬链接和软链接(符号链接) ...

  3. class、interface、struct的区别

    1 struct和class有什么区别 1.1默认的继承访问权限 Struct是public的,class是private的. 你可以写如下的代码: struct A { char a; }; str ...

  4. Axis2 webservice入门--写个简单的webservice

    上一篇介绍了webservice开发前的准备.下面开始写webservice.如果不了解axis2请看上一篇,如果是新手:建议一边看一边写代码,自己动手完成这个过程. 一.新建一个web项目 二.新建 ...

  5. 使用Join代替In

    我们知道,在sql中使用IN让我们的where子句可以规定多个值.当需要从一个集合中查询包含某几个值的记录的时候,通常我们会选择使用IN来实现,其实,使用JOIN也可以实现这样的功能,而且性能要比IN ...

  6. 让DIV实现抖动效果!

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  7. bzoj3594: [Scoi2014]方伯伯的玉米田

    dp新优化姿势... 首先,当我们拔高时,一定右端点是n最优.因为如果右端点是r,相当于降低了r之后玉米的高度.显然n更优. 那么可以dp.dp[i][j]表示前i个拔高j次的LIS.dp[i][j] ...

  8. js基础之事件

    一.event对象 document.onclick=function(ev){ oEvent=event?event:ev;//兼容性写法 alert(oEvent.clientX); alert( ...

  9. 修改PE文件的入口函数OEP

    修改入口函数地址.这个是最省事的办法,在原PE文件中新增加一个节,计算新节的RVA,然后修改入口代码,使其指向新增加的节.当然,如果.text节空隙足够大的话,不用添加新节也可以. BOOL Chan ...

  10. 【个人使用.Net类库】前言

    个人接触.Net是在2013年8月份到了一家新的公司开始的. 目前为止,发现自己的知识储备如下: 基本的WinForm编程,但没做过对应项目. 基本的Asp.Net页面,做过查询.树形菜单.登录的小功 ...