C#利用HttpWebRequest,Stream,HttpWebResponse,StreamReader获取post返回的数据
来源:互联网 发布:乐知英语官网下载 编辑:程序博客网 时间:2024/06/07 00:24
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Net;using System.IO;namespace TestCon{ static class InfoGeter { //静态方法传递两个参数,Post_String是单纯的链接,Post_Data是post的参数用以请求 public static string Info_Geter_Post_Get(string Post_String,string Post_Data) { try { string s_Connection_String = Post_String; //实例化一个HttpWebrequst对象 HttpWebRequest Info_Request = (HttpWebRequest)WebRequest.Create(s_Connection_String); //设置Requst的模式 Info_Request.Method = "POST"; //设置Content-Type Http标头的值,该值为默认值 Info_Request.ContentType = "application/x-www-form-urlencoded"; //预设响应等待时间 Info_Request.Timeout = 20000; //建立一个Stream对象来写入Requst请求的参数流内涵url和key值等 Stream Info_Stream = Info_Request.GetRequestStream(); //调用Write方法第一个参数是获取传递参数的值得类型,第二个是流起始位置,第三个参数指流的长度 Info_Stream.Write(Encoding.UTF8.GetBytes(Post_Data), 0, Encoding.UTF8.GetBytes(Post_Data).Length); //实例化一个HttpWebResponse用GetResponse方法用以获取服务器返回的响应 HttpWebResponse Info_Response = (HttpWebResponse)Info_Request.GetResponse(); //实例化一个StreamReader对象来获取Response的GetResponseStream返回的响应的体 StreamReader Info_Reader = new StreamReader(Info_Response.GetResponseStream(), Encoding.UTF8); return Info_Reader.ReadToEnd()+""; } catch (System.Exception ex) { Console.WriteLine(ex); Console.ReadLine(); return ""; } } }}
0 0
- C#利用HttpWebRequest,Stream,HttpWebResponse,StreamReader获取post返回的数据
- C#中HttpWebRequest与HttpWebResponse的使用方法
- C#中HttpWebRequest与HttpWebResponse的使用方法
- C#中HttpWebRequest与HttpWebResponse的使用方法
- C#中HttpWebRequest与HttpWebResponse的使用方法
- C# 利用HttpWebRequest模拟登陆获取数据设置Accept-Encoding为gzip,deflate后返回的网页是乱码处理
- c# HttpWebRequest与HttpWebResponse
- c# HttpWebRequest与HttpWebResponse
- c# HttpWebRequest与HttpWebResponse
- C#模拟POST提交表单(二)--HttpWebRequest以及HttpWebResponse
- C#模拟POST提交表单--HttpWebRequest以及HttpWebResponse
- C#模拟POST提交表单--HttpWebRequest以及HttpWebResponse
- C#模拟POST提交表单(二)--HttpWebRequest以及HttpWebResponse
- 用httpwebrequest/httpwebresponse向服务器POST发送及接收数据
- 用httpwebrequest/httpwebresponse向服务器POST发送及接收数据
- c# HttpWebRequest与HttpWebResponse请求网页和返回网页教程
- C# 利用 HttpWebRequest 和 HttpWebResponse 模拟登录有验证码的网站
- 黄聪:C#模拟网站页面POST数据提交表单(二)--HttpWebRequest以及HttpWebResponse (转)
- Impala的中文翻译链接
- MongoDB学习整理
- 谨防全角空格
- ORACLE 创建作业JOB例子
- 86. Partition List
- C#利用HttpWebRequest,Stream,HttpWebResponse,StreamReader获取post返回的数据
- Android 关于getView方法中ViewHolder类static修饰符
- Spring Cache之Ehcache和Memcached
- dubbo相关知识(五)-- RPC详解
- Tomcat CXF 启动停止问题
- WebService的调用
- Struts2学习(四)OGNL标签介绍
- Windows7 安装scrapy 简单实用教程
- android studio webview加载网页