static string get_html(string url)
{
var request = WebRequest.Create(url);
var response = request.GetResponse();
var html = "";
using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
html = sr.ReadToEnd();
}
return html;
}
   public static string PostData()
{
var html = "";
var account = "xxxx"; var sign = md5(pwd);
string postdata = string.Format("Account={0}&Sign={1}", account, sign);
//****************
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:4500/xxxx.ashx");
httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Method = "POST";
httpWebRequest.Timeout = ;
byte[] btBodys = Encoding.UTF8.GetBytes(postdata);
httpWebRequest.ContentLength = btBodys.Length;
httpWebRequest.GetRequestStream().Write(btBodys, , btBodys.Length);
//****************
var response = httpWebRequest.GetResponse();
using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
html = sr.ReadToEnd();
}
return html; }

WebRequest的get及post提交的更多相关文章

  1. WebRequest请求错误(服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF)

    WebRequest请求错误(服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF)解决办法,天津config文件,增加一个配置如下 <?x ...

  2. .NET接入接口/请求服务器

    之前只调用过自己写的接口,这个是调用外部接口 一.创建方法链接接口 , string method = "Get", string token = null) { if (stri ...

  3. AspNet Core Api Restful +Swagger 实现微服务之旅 (三)

    (1)  访问Rest ful接口时 Token验证  返回数据格式封装 (一)访问时Token验证  返回数据格式封装 1.1访问Api接口 方法 实现         1.1.1 创建访问Rest ...

  4. 代码积累-Common

    新建Common类库 /// <summary> /// string的扩展 /// </summary> public static class StringExt { // ...

  5. 接口调用,输出结果为Json格式(ConvertTo-Json),提交参数给URL(WebRequest)

    1.直接输出为json格式: Get-Process -Id $pid | ConvertTo-Json | clip.exe 2.自定义结果为json格式: $serverinfoj = @&quo ...

  6. C# WebService服务Post提交

    public string WebServerTest(string PostData) { PostData = "jsonData=" + PostData; string P ...

  7. Post提交

    以下两种Post提交方法都可行 /// <summary> /// post 数据 /// </summary> /// <param name="url&qu ...

  8. .Net模拟提交表单

    2016-09-0210:49:20 以中邮速递API为服务接口,由于提交方式为表单提交,我要获取返回值来处理其他业务,所以一开始尝试采用Js后台获取返回值,但是涉及到跨域请求限制问题,那边服务端接口 ...

  9. C#的提交表单方式主要有两种WebClient与HttpWebRequest

    根据黄聪:C#模拟网站页面POST数据提交表单(转) using System; using System.Collections.Generic; using System.IO; using Sy ...

随机推荐

  1. php尝试调用一个图灵机器人

    1.需要到图灵机器人的网址,去注册一下账号.网址:http://www.tuling123.com/sso-web/index.html?ReturnURL=http%3A%2F%2Fwww.tuli ...

  2. Oracle远程数据建物化视图(materialized)创建简单记录,以及DBLINK的创建

    目的:实现远程数据库访问及其相应表的定时同步 一.远程数据库dblink的创建 select * from dba_db_links; select * from user_sys_privs;--查 ...

  3. C++下遍历文件夹

    编写程序遍历文件夹及其子文件夹下所有文件,并输出到标准输出流或者文件流. 1. 先考虑在单层目录下,遍历所有文件.以C:\WINDOWS为例: 用到数据结构_finddata_t,文件信息结构体的指针 ...

  4. (转)Linux服务器SNMP常用OID

    原文:https://www.haiyun.me/archives/linux-snmp-oid.html 收集整理一些Linux下snmp常用的OID,用做服务器监控很不错.服务器负载: 1 2 3 ...

  5. Yii “CDbConnection failed to open the DB connection: could not find driver"解决办法

    前言:用Yii框架做项目时,有时会遇到“CDbConnection failed to open the DB connection: could not find driver”这个问题,这个问题通 ...

  6. datepicker97切换年月日再连续点击下拉中日期的bug出现问题

    解决办法: function wdateOption(fmt){ if(fmt===undefined){fmt="yyyy-MM-dd"} return{ dateFmt:fmt ...

  7. <数据挖掘导论>读书笔记2

    1.频率和众数 frequency(vi)=具有属性值vi的对象数/m 分类属性的众数mode是具有最高频率的值. 2.百分位数 3.位置度量:均值和中位数 4.散布度量:极差和方差 绝对平均偏差 A ...

  8. ES6中的类继承和ES5中的继承模式详解

    1.ES5中的继承模式 我们先看ES5中的继承. 既然要实现继承,首先我们得要有一个父类. Animal.prototype.eat = function(food) { console.log(th ...

  9. html空白文字宽度

    原文链接 名称 编号 描述     不断行的空白(1个字符宽度)     半个空白(1个字符宽度)     一个空白(2个字符宽度)     窄空白(小于1个字符宽度) 小写加分号!

  10. 插入排序——Python实现

    一.排序思想 排序思想参见:https://www.cnblogs.com/luomeng/p/10583124.html 二.python实现 def InsertSort(arrs): " ...