C#中Post和Get提交
1、Post提交
private string PostWebRequest(string Url, string paramData, string dataEncode)
{
string ret = string.Empty;
try
{
Encoding myEncoding = Encoding.GetEncoding(dataEncode);
byte[] byteArray = myEncoding.GetBytes(paramData); //转化
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(Url);
webReq.Method = “POST”;
webReq.ContentType = "application/x-www-form-urlencoded"; webReq.ContentLength = byteArray.Length;
Stream newStream = webReq.GetRequestStream();
newStream.Write(byteArray, , byteArray.Length);//写入参数
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(), myEncoding);
ret = sr.ReadToEnd();
sr.Close();
response.Close();
}
catch (Exception ex)
{
WriteFileLog(ex.ToString());
MessageBox.Show(ex.Message);
}
return ret;
}
2、Get提交
private string GetWebRequest(string Url, string paramData, string dataEncode)
{
string requestString = "";
try
{
string reallyUrl = Url; Encoding myEncoding = Encoding.GetEncoding(dataEncode);
// CookieContainer cookieContainer = new CookieContainer();
HttpWebRequest request = WebRequest.Create(reallyUrl) as HttpWebRequest;
// ServicePointManager.CheckCertificateRevocationList = false;
request.Method = “GET”;
// request.KeepAlive = false;
// request.AllowAutoRedirect = true;
request.ContentType = "application/x-www-form-urlencoded"; HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader responseStream = new StreamReader(response.GetResponseStream(), myEncoding);
requestString = responseStream.ReadToEnd();
response.Close();
responseStream.Close();
}
catch (Exception ex)
{ WriteFileLog(ex.ToString());
MessageBox.Show(ex.Message);
}
C#中Post和Get提交的更多相关文章
- jsp中普通按钮如何提交表单
jsp中普通按钮如何提交表单方法1: <form action = "提交的地址"> <input type="submit" ...
- struts2中token防止重复提交表单
struts2中token防止重复提交表单 >>>>>>>>>>>>>>>>>>>&g ...
- 详解OJ(Online Judge)中PHP代码的提交方法及要点【举例:ZOJ 1001 (A + B Problem)】
详解OJ(Online Judge)中PHP代码的提交方法及要点 Introduction of How to submit PHP code to Online Judge Systems Int ...
- js jq输入框中按回车触发提交事件,用户在页面输入后按回车(Enter键)进行
js jq输入框中按回车触发提交事件,用户在页面输入后按回车(Enter键)进行 代码如下: <!DOCTYPE html> <html lang="en" xm ...
- 如何永久删除git仓库中敏感文件的提交记录
如何永久删除git仓库中敏感文件的提交记录 参考: 1. https://help.github.com/articles/remove-sensitive-data/
- YARN 中的应用程序提交
YARN 中的应用程序提交 本节讨论在应用程序提交到 YARN 集群时,ResourceManager.ApplicationMaster.NodeManagers 和容器如何相互交互.下图显示了一个 ...
- 在Action中获取表单提交数据
-----------------siwuxie095 在 Action 中获取表单提交数据 1.之前的 Web 阶段是提交表单到 Servlet,在其中使用 Request 对象 的方法获取数据 2 ...
- IDEA中Git的更新/提交/还原方法
记录一下在IDEA上怎样将写的代码提交到GitHub远程库: 下面这个图是基本的提交代码的顺序: 1. 将代码Add到stage暂存区本地修改了代码后,需先将代码add到暂存区,最后才能真正提价到gi ...
- iframe中使用模态框提交表单后,iframe加载父页面的解决方法
在iframe中使用模态框提交表单后,会出现iframe加载整个父页面的问题,如下图: 解决方法: 在form表单中添加target属性 _parent 这个属性会使目标文档载入父窗口或者包含来超链接 ...
- ajaxSubmit 页面生成的html 中含有表单提交表单方式
$("#form_title").ajaxSubmit({ //页面生成的html 中含有表单提交表单方式 dataType: "json", success ...
随机推荐
- codeforce好地方啊 Bear and Elections *
Codeforces Round #318 居然可以看测试数据,哪里没过一目了然,哈哈哈 #include<cstdio> #include<iostream> #includ ...
- ASP.NET的新成员ASP.NET WebHooks
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:前几天微软除了发布了ASP.NET 5的Beta7之外,还有一个值得关注的东西,就是A ...
- C结构体中数据的内存对齐问题
转自:http://www.cnblogs.com/qwcbeyond/archive/2012/05/08/2490897.html 32位机一般默认4字节对齐(32位机机器字长4字节),64位机一 ...
- easyui tree折叠
标签 <div id="buildDiv" data-options="region:'center'" title="楼栋权限" s ...
- Java学习笔记(三)——运算符
一.运算符: 1.分类: 2.java中的运算符 (1)其中,++在左,表示先加了再用,++在右,表示先用了再加. (2)% 用来求余数,也称为"取模运算符" 3.赋值运算符 4. ...
- C#的Enum——枚举
枚举 枚举类型声明为一组相关的符号常数定义了一个类型名称.枚举用于“多项选择”场合,就是程序运行时从编译时已经设定的固定数目的“选择”中做出决定. 枚举类型(也称为枚举)为定义一组可以赋给变量的命名整 ...
- Android拓展系列(10)--使用Android Studio阅读整个Android源码
之前一直在windows下用source insight阅读android源码,效果非常好.后来远程异地服务器,网络限制,一直用ssh + vim,现在主要还是以这种方式.最近发现一个不错的东西(早就 ...
- hdu1087 最大递增子段和
http://acm.split.hdu.edu.cn/showproblem.php?pid=1087 状态方程:sum[j]=max{sum[i]}+a[j]; 其中,0<=i<=j, ...
- js-其他
- 关于DOM
前言 DOM的作用是将网页转为一个javascript对象,从而可以使用javascript对网页进行各种操作(比如增删内容).浏览器会根据DOM模型,将HTML文档解析成一系列的节点,再由这些节点组 ...