WebRequest的get及post提交
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提交的更多相关文章
- WebRequest请求错误(服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF)
WebRequest请求错误(服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF)解决办法,天津config文件,增加一个配置如下 <?x ...
- .NET接入接口/请求服务器
之前只调用过自己写的接口,这个是调用外部接口 一.创建方法链接接口 , string method = "Get", string token = null) { if (stri ...
- AspNet Core Api Restful +Swagger 实现微服务之旅 (三)
(1) 访问Rest ful接口时 Token验证 返回数据格式封装 (一)访问时Token验证 返回数据格式封装 1.1访问Api接口 方法 实现 1.1.1 创建访问Rest ...
- 代码积累-Common
新建Common类库 /// <summary> /// string的扩展 /// </summary> public static class StringExt { // ...
- 接口调用,输出结果为Json格式(ConvertTo-Json),提交参数给URL(WebRequest)
1.直接输出为json格式: Get-Process -Id $pid | ConvertTo-Json | clip.exe 2.自定义结果为json格式: $serverinfoj = @&quo ...
- C# WebService服务Post提交
public string WebServerTest(string PostData) { PostData = "jsonData=" + PostData; string P ...
- Post提交
以下两种Post提交方法都可行 /// <summary> /// post 数据 /// </summary> /// <param name="url&qu ...
- .Net模拟提交表单
2016-09-0210:49:20 以中邮速递API为服务接口,由于提交方式为表单提交,我要获取返回值来处理其他业务,所以一开始尝试采用Js后台获取返回值,但是涉及到跨域请求限制问题,那边服务端接口 ...
- C#的提交表单方式主要有两种WebClient与HttpWebRequest
根据黄聪:C#模拟网站页面POST数据提交表单(转) using System; using System.Collections.Generic; using System.IO; using Sy ...
随机推荐
- 第十一次 Scrum Meeting
第十一次 Scrum Meeting 写在前面 会议时间 会议时长 会议地点 2019/4/18 21:00 20min 大运村1号楼6F 附Github仓库:WEDO 例会照片 工作情况总结 人员 ...
- 封装通用的xhr对象(兼容各个版本)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Ubuntu 18.04上搭建FTP服务器
1.准备工作需要安装并运行的Ubuntu Server 18.04系统.当然还需要一个具有sudo权限的账号. 2.安装VSFTPVSFTP程序位于标准存储库中,因此可以使用单个命令删除安装.打开终端 ...
- C# GridView 导出Excel表
出错1:类型“GridView”的控件“GridView1”必须放在具有 runat=server 的窗体标记内解决方案:在后台文件中重载VerifyRenderingInServerForm方法,如 ...
- Eclipse的简单的用法大全
Eclipse我认为最重要的功能:断点调试 Debug的作用: 调试程序并且查看程序的执行流程 如何查看程序执行的流程 断点(就是一个标记,表示从哪里开始) 设置断点(在你想要断点的代码的左边双击即可 ...
- LinuxShell脚本编程基础2-变量与数值运算、父shell和子shell
1.变量和数值运算 Shell脚本的变量不需要声明的 对变量赋值有两种方式, 直接用“=” 或者用键盘输入值 #!/bin/bash name1="Jack" echo $name ...
- 阿里云Centos7上安装MySQL教程
1 基本安装过程 1.查看系统是否安装了mysql软件 # rpm -qa|grep -i mysql 2.将已经安装过的软件卸载掉.注意:这样的卸载是不彻底,不过这里够用了 # yum remove ...
- 深入理解BSS(Block Started by Symbol)
理解ELF的BSS section, 可以概括为: Uninitialized global/static data "Block Started by Symbol" " ...
- Mybatis Dao开发的两种方式(一)
原始Dao的开发方式: 1.创建数据库配置文件db.properties jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localh ...
- Learning Linux Commands: awk--reference
http://how-to.linuxcareer.com/learning-linux-commands-awk 1. Introduction In this case, the title mi ...