c#发送http请求get post
来源:互联网 发布:淘宝hd历史版本 编辑:程序博客网 时间:2024/05/17 08:16
using System;using System.IO;using System.Net; public string HttpPost(string Url, string postDataStr) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr); request.CookieContainer = cookie; Stream myRequestStream = request.GetRequestStream(); StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312")); myStreamWriter.Write(postDataStr); myStreamWriter.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Cookies = cookie.GetCookies(response.ResponseUri); Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); string retString = myStreamReader.ReadToEnd(); myStreamReader.Close(); myResponseStream.Close(); return retString; } public string HttpGet(string Url, string postDataStr) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr); request.Method = "GET"; request.ContentType = "text/html;charset=UTF-8"; //在http请求中附加cookie,服务端可以通过$_COOKIE获取 request.Headers["Cookie"] = "Url=http://dotnet.aspx.cc; UserInfo=UserName=" + System.Web.HttpUtility.UrlEncode("孟宪会") + ";UserId=net_lover"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream myResponseStream = response.GetResponseStream(); StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); string retString = myStreamReader.ReadToEnd(); myStreamReader.Close(); myResponseStream.Close(); return retString; }
0 0
- c#发送http请求get post
- HTTP 发送get post请求
- http发送get、post请求
- Http发送GET/POST请求
- C#模拟http 发送post或get请求
- C#模拟http 发送post或get请求
- C#模拟http 发送post或get请求
- C#模拟http 发送post或get请求
- C#模拟http 发送post或get请求
- C#模拟发送http get、post请求的方式
- C#模拟http 发送post或get请求
- C#模拟http 发送post或get请求
- C#模拟http 发送post或get请求
- C#模拟http 发送POST或GET请求
- C#模拟http 发送post或get请求
- C#模拟http 发送post或get请求
- JAVA 发送Http请求,GET、POST请求
- java发送HTTP GET POST请求
- 汇总:薪资从千到万是如何炼成的
- JS模块化编程
- Github for Windows使用图文教程
- LeetCode - Insertion Sort List
- mma7660(重力感应传感器)
- c#发送http请求get post
- Android获取View在屏幕中的位置
- 开源网络通讯库参考
- linux文件权限学习笔记
- 互联网从业者必读:长时间工作意味着什么
- 梦想经不起等待,今天起就行动吧!
- php和Mysql web开发 第一章 php快速入门
- ucosii在stm32上的移植详解1
- (007):使用LINQ进行数据转换(C#)