get请求url

#region GetHttp请求
/// <summary>
/// GetHttp请求
/// </summary>
/// <param name="url">GetUrl</param>
/// <returns></returns>
public static string HttpWebResponse_Get(string url)
{
string strRet = null;
try
{
string strUrl = url;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strUrl);
request.Timeout = ;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.IO.Stream resStream = response.GetResponseStream();
Encoding encode = System.Text.Encoding.UTF8;
StreamReader readStream = new StreamReader(resStream, encode);
Char[] read = new Char[];
int count = readStream.Read(read, , );
while (count > )
{
String str = new String(read, , count);
strRet = strRet + str;
count = readStream.Read(read, , );
}
resStream.Close();
}
catch (Exception e) { } return strRet;
} #endregion

Post请求

#region PostHttp请求
/// <summary>
/// PostHttp请求
/// </summary>
/// <param name="postData">post数据</param>
/// <param name="url">postUrl</param>
public static string HttpWebResponse_Post(string postData, string url)
{ string result = null;
try
{
//string postData = "{\"tableName\":\"" + tableName + "\",\"tableId\": \"" + tableId + "\"}";
Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
UTF8Encoding encoding = new UTF8Encoding();
byte[] bytes = encoding.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = bytes.Length;
Stream writeStream = request.GetRequestStream();
writeStream.Write(bytes, , bytes.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
{
result = readStream.ReadToEnd();
readStream.Close();
}
} writeStream.Close();
return result;
}
catch (Exception)
{
}
return result;
}
#endregion

HttpWebRequest get/post方法实现的更多相关文章

  1. httpwebrequest 用GET方法时报无法发送具有此谓词类型的内容正文

    如下一段小程序,运行结果报无法发送具有此谓词类型的内容正文的错误,其实原因很简单,因为用的是GET的方式进行提交,而GetRequestStream()是用来在post提交的时候写post的内容的流, ...

  2. 十二、.net core(.NET 6)添加通用的访问webapi的方法(包括HttpClient和HttpWebRequest)

    开发通用的访问webapi方法. 在common工具文件夹下,新建一个类库项目:Wsk.Core.WebHelper,并引用Package包项目,然后新建一个类HttpClientHelper,用于使 ...

  3. HttpWebRequest.AddRange 支持long类型

    很久很久以前,在哪个FAT32格式还流行的年代,文件大小普遍还没超过4G的年代,.Net已经出来了. 而那时候.Net实现的HTTP断点续传协议,还没预料到如此普及(我猜的).那时候的HttpWebR ...

  4. C#获取网页内容的三种方式

    C#通常有三种方法获取网页内容,使用WebClient.WebBrowser或者HttpWebRequest/HttpWebResponse... 方法一:使用WebClient (引用自:http: ...

  5. C#编程总结(十二)断点续传

    C#编程总结(十二)断点续传 我们经常使用下载工具,如bit精灵.迅雷.FlashGet,这些软件都支持断点续传. 断点续传即下载任务暂停后可以继续,而无需重新下载,即下载时需要通知服务器的起始位置. ...

  6. 一个服务器上面配置多个IP ,实现指定IP的域名请求

    //配置多个IP命名using System.Net; //********************************************************************** ...

  7. c#获取url请求的返回值(转)

    有两种方式获取. 方法一: /// <summary> /// 获取url的返回值 /// </summary> /// <param name="url&qu ...

  8. C#容易忽略點--包含多線程 委託事件等等--此頁面bug,編輯能查看全部內容

    委託事件 http://www.cnblogs.com/sdya/p/5217635.html 反射 1 创建用于反射使用的DLL 新建一个C#类库项目,拷贝源代码如下,编译生成DLL(假如DLL的文 ...

  9. C#编程断点续传

    C#编程总结(十二)断点续传 Posted on 2014-02-16 10:56 停留的风 阅读(384) 评论(3) 编辑 收藏 C#编程总结(十二)断点续传 我们经常使用下载工具,如bit精灵. ...

随机推荐

  1. Swift - 30 - 可变参数

    //: Playground - noun: a place where people can play import UIKit // 可变参数一定要放在所有定义参数的最后面, 和其他参数的定义方式 ...

  2. Delphi 动态创建组件,单个创建、单个销毁

    效果图如下: 实现部分代码如下: var rec: Integer = 0; //记录增行按钮点击次数 implementation {$R *.dfm} //动态释放单个组件内存,即销毁组件 pro ...

  3. ibatis ORA-00911: 无效字符

    检查下xml文件中 sql的最后是不是写了 “;” 最容易犯这个毛病,都不知道吃了多少次亏了. 什么ORA-00911: 无效字符 什么The error occurred while applyin ...

  4. ViewData与ViewBag比较

    在Asp.net MVC 3 web应用程序中,我们会用到ViewData与ViewBag,对比一下: ViewData ViewBag 它是Key/Value字典集合 它是dynamic类型对像 从 ...

  5. javascript 向上滚动

    <html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Co ...

  6. Oracle归档日志定时删除任务

    1.在Oracle账号下,创建归档日志删除文件del_arch.sh 文件位置:/home/oracle/crontabOra,内容如下: #!/bin/bash LOG_DIR=/home/orac ...

  7. Linux的时钟管理

    本文转自博客园zhenwenxian的Linux时间管理,很详细,写得很不错,对初学者还是有很大帮助的. 时间管理在内核中占有非常重要的地位.相对于事件驱动,内核中有大量的函数都是基于时间驱动的.内核 ...

  8. 在CentOS6上使用YUM安装php5.5.x

    这里使用 Webtatic EL6的YUM源来安装php5.5,我们首页安装Webtatic EL6 YUM源 rpm -Uvh http://repo.webtatic.com/yum/el6/la ...

  9. poj 2031Building a Space Station

    http://poj.org/problem?id=2031 #include<cstdio> #include<cstring> #include<cmath> ...

  10. SCALA中的函数式编程

    演示了值函数,匿名函数,闭包... 其它具体的应用,还得在生产当中吧.. 这个告一段落..其它SAM,CURRY,高阶函数,集合,泛型,隐式类..这些,还是找专门的书去深入了解啦... C:\User ...