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提交的更多相关文章

  1. jsp中普通按钮如何提交表单

    jsp中普通按钮如何提交表单方法1: <form action = "提交的地址">         <input type="submit" ...

  2. struts2中token防止重复提交表单

    struts2中token防止重复提交表单 >>>>>>>>>>>>>>>>>>>&g ...

  3. 详解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 ...

  4. js jq输入框中按回车触发提交事件,用户在页面输入后按回车(Enter键)进行

    js jq输入框中按回车触发提交事件,用户在页面输入后按回车(Enter键)进行 代码如下: <!DOCTYPE html> <html lang="en" xm ...

  5. 如何永久删除git仓库中敏感文件的提交记录

    如何永久删除git仓库中敏感文件的提交记录 参考: 1. https://help.github.com/articles/remove-sensitive-data/

  6. YARN 中的应用程序提交

    YARN 中的应用程序提交 本节讨论在应用程序提交到 YARN 集群时,ResourceManager.ApplicationMaster.NodeManagers 和容器如何相互交互.下图显示了一个 ...

  7. 在Action中获取表单提交数据

    -----------------siwuxie095 在 Action 中获取表单提交数据 1.之前的 Web 阶段是提交表单到 Servlet,在其中使用 Request 对象 的方法获取数据 2 ...

  8. IDEA中Git的更新/提交/还原方法

    记录一下在IDEA上怎样将写的代码提交到GitHub远程库: 下面这个图是基本的提交代码的顺序: 1. 将代码Add到stage暂存区本地修改了代码后,需先将代码add到暂存区,最后才能真正提价到gi ...

  9. iframe中使用模态框提交表单后,iframe加载父页面的解决方法

    在iframe中使用模态框提交表单后,会出现iframe加载整个父页面的问题,如下图: 解决方法: 在form表单中添加target属性 _parent 这个属性会使目标文档载入父窗口或者包含来超链接 ...

  10. ajaxSubmit 页面生成的html 中含有表单提交表单方式

    $("#form_title").ajaxSubmit({ //页面生成的html 中含有表单提交表单方式 dataType: "json", success ...

随机推荐

  1. SVN-简要说明

    SVN官方推荐在一个版本库的根目录下先建立trunk.branches.tags这三个文件夹,其中trunk是开发主干,存放日常开发的内容:branches存放各分支的内容,比如为不同客户定制的不同版 ...

  2. POJ 1655 Balancing Act 树的重心

    Balancing Act   Description Consider a tree T with N (1 <= N <= 20,000) nodes numbered 1...N. ...

  3. windows下mongodb安装与使用整理

    一.首先安装mongodb 1.下载地址:http://www.mongodb.org/downloads 2.解压缩到自己想要安装的目录,比如d:\mongodb 3.创建文件夹d:\mongodb ...

  4. 经典贪心算法uva11729

    uva11729 这个题的题意是 你有n个部下,每个部下需要完成一项任务.第i个部下需要你花Bi分钟交代任务,然后他会立刻独立地.无间断地执行Ji分钟后完成任务. 你需要选择交待任务的顺序,使得所有任 ...

  5. Java会出现"unreachable code"错误的几个例子

    public class exam { static int num=5; static int m1(){ try{ num=6; throw new NullPointerException(); ...

  6. js总结-面向对象编程,DOM,BOM

  7. 试听笔记:技术狂人nodejs

    nodejs概念: 让javascript运行在服务端的开发平台.不是一种语言,不是框架,不是库.特点:单线程异步.事件驱动. PHP.JAVA既是语言也是平台. 创始人:Ryan nodejs cm ...

  8. 操作TAB文件和TStringGrid赋值;

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  9. 后缀数组 POJ 1743 Musical Theme

    题目链接 题意:给定n个数字,求超过5个数字的,最长的,变化相同的,不相交的重复子串 分析:男人8题中的一题!数列相邻两项做差,形成新数列,即求数列中的最长重复子串(不可相交). 后缀数组+二分答案. ...

  10. Python基础11- 函数之自定义函数

    自定义函数语法结构:def fun1([x],[y],....): 语句1 语句2 使用def语句来定义函数,在def后依次写出函数名.小括号.参数(可无).冒号,然后缩进写函数体 1.无参函数:de ...