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 ...
随机推荐
- Mastache.js学习笔记(转自小花喵)
简单的记录我使用Mastache的使用. 为什么使用JS模板引擎? 当数据结构复杂,Js的拼接凌乱,难以维护,但是又需要通过ajax加载数据的时候: 而Mastache的上手难度不高,并符合大部分业务 ...
- 差分ADC到单端ADC
单片机可以处理单端ADC(不在电压范围内要进行分压),也可以处理差分ADC(但需要双路输入).差分信号在传输过程中抗共模干扰能力很强,所以传输中都用差分传输,到ADC时可以差分也可以单端(需要放大器处 ...
- CodingLife的CSS样式整理
1 首页的超链接鼠标悬停效果 .postTitle a:hover { color:red; text-decoration:none } 2 正文标题鼠标悬停效果 #topics .postTitl ...
- 转 linux 内存释放
原文 http://blog.zol.com.cn/2322/article_2321774.html #cat /proc/meminfo | grep "MemFree" | ...
- JSP页面GET传值乱码问题
两个JSP页面进行GET传值的时候.两个页面的编码都是UTF-8,且传值之前设置response的content为UTF-8也解决不了问题. 设置tomcat的配置文件server.xml:在Conn ...
- window server 搭建git服务器
Git服务器Gogs简易安装-Windows环境 1.下载git for windows 1 https://github.com/git-for-windows/git/releases/dow ...
- unity Socket TCP连接案例(一)
非常清晰的demo 服务端 using System; using System.Collections; using System.Collections.Generic; using System ...
- 二叉树数组C++实现
基本概念梳理 孩子:子结点 双亲:父节点 度:有多少个子结点 有序树:固定的排列的树 无序树:排列与顺序无关的树 二叉树:所有结点小于等于2的树 源代码:https://github.com/cjy5 ...
- Java入门系列-27-反射
咱们可能都用过 Spring AOP ,底层的实现原理是怎样的呢? 反射常用于编写工具,企业级开发要用到的 Mybatis.Spring 等框架,底层的实现都用到了反射.能用好反射,就能提高我们编码的 ...
- Java入门系列-13-String 和 StringBuffer
这篇文章带你学会字符串的日常操作 String类 字符串在日常生活中无处不在,所以掌握字符串的使用至关重要. 使用 String 对象存储字符串,String 类位于 java.lang 包中,jav ...