php 得到ashx,C# Post 一般处理程序(ashx)并得到返回值
C# Post 一般处理程序(ashx)并得到返回值
发布日期:2018-02-09 浏览次数:1500
var postUrl = "**/LoginInfo.ashx";
var postString = "method=CheckPW&id=4454556289&pwd=&checkword=8888&sign=";
HttpWebRequest httpRequset = null;
HttpWebResponse httpResponse = null;
try
{
//POST登录信息获取返回结果,结果为0是为登录成功
httpRequset = (HttpWebRequest)HttpWebRequest.Create(postUrl);//创建http 请求
httpRequset.Method = "POST";//POST 提交
httpRequset.ContentType = "application/x-www-form-urlencoded";//以上信息在监听请求的时候都有的直接复制过来
httpRequset.Headers.Add("X-Requested-With", "XMLHttpRequest");
httpRequset.Accept = "*/*";
httpRequset.Referer = "***";
httpRequset.Headers.Add("Accept-Language", "zh-Hans-CN,zh-Hans;q=0.7,ja;q=0.3");
httpRequset.Headers.Add("Accept-Encoding", "gzip, deflate");
httpRequset.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko";
httpRequset.KeepAlive = true;
httpRequset.Host = "xxx.com";
//httpRequset.Headers.Add("Access-Control-Allow-Origin", "*");//可跨域
httpRequset.Headers.Add("Pragma", "no-cache");
httpRequset.Headers.Add("DNT", "1");
httpRequset.ServicePoint.Expect100Continue = false;
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(postString);
httpRequset.ContentLength = bytes.Length;
Stream stream = httpRequset.GetRequestStream();
stream.Write(bytes, 0, bytes.Length);
stream.Close();//以上是POST数据的写入
httpResponse = (HttpWebResponse)httpRequset.GetResponse();//获得 服务端响应
var s = string.Empty;
using (Stream responsestream = httpResponse.GetResponseStream())
{
using (StreamReader sr = new StreamReader(responsestream, System.Text.Encoding.UTF8))
{
content = sr.ReadToEnd(); //返回信息
}
//WebClient 写法
WebClient webClient = new WebClient();
NameValueCollection formData = new NameValueCollection();
formData["username"] = "testuser";
formData["password"] = "mypassword";
byte[] responseBytes = webClient.UploadValues(postUrl , "POST", formData);
string responsefromserver = Encoding.UTF8.GetString(responseBytes);
Console.WriteLine(responsefromserver);
webClient.Dispose();
非特殊说明,本文版权归原作者所有,转载请注明出处
提示:本站所有资源仅供学习与参考,请勿用于商业用途。图片来自互联网~如侵犯您的权益,请联系QQ:1067507709.
php 得到ashx,C# Post 一般处理程序(ashx)并得到返回值相关推荐
- ASP.NET中使用一般处理程序ashx作为后台处理实现响应get和post请求
场景 ASP.NET中新建Web网站并部署到IIS上(详细图文教程): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/107199 ...
- [.ashx檔?泛型处理程序?]基础入门#5....ADO.NET 与 将DB里面的二进制图片还原 (范例下载 大型控件的ImageField)...
[.ashx檔?泛型处理程序?]基础入门#5....ADO.NET 与 将DB里面的二进制图片还原 (范例下载 & 大型控件的ImageField) http://www.dotblogs.c ...
- 一般处理程序(ashx)和页面处理程序(aspx)的区别
客官请看图 图中的Httphandler就是处理程序. 两者的共同点 如果把aspx处理程序和ashx处理程序放到上图中,他们是处在相同的位置的, 他们都实现了IHttphandler接口.实现了IH ...
- C# 一般处理程序 ashx文件
aspx:Web窗体设计页面.Web窗体页由两部分组成:视觉元素(html.服务器控件和静态文本)和该页的编程逻辑(VS中的设计视图和代码视图可分别看到它们对应得文件).VS将这两个组成部分分别存储在 ...
- C#——文件上传(一般处理程序ashx)
Framework版本:.Net Framework 4 1.FileInfo实体 using System; using System.Collections.Generic; using Syst ...
- ashx页面中context.Session[xxx]获取不到值的解决办法
1.在 aspx和aspx.cs中,都是以Session["xxx"]="aaa"和aaa=Session["xxx"].ToString( ...
- ashx 跨域_使用ashx解决ajax跨域访问的问题
由于跨域访问是被IE的安全访问拒绝掉的 需要使用web代理 新建一个proxy.ashx文件 在proxy.ashx里建一个webservice 代码如下: [WebService(Namespace ...
- ashx 跨域_使用ashx解决ajax跨域访问的问题 | 学步园
由于跨域访问是被IE的安全访问拒绝掉的 需要使用web代理 新建一个proxy.ashx文件 在proxy.ashx里建一个webservice 代码如下: [WebService(Namespace ...
- ashx 修改部分 html,html+ashx 表单提交示例
1,sumbit表单提交 WebForm1.aspx源码: submitForm.ashx源码: using System; using System.Collections.Generic; usi ...
最新文章
- php中的css样式改变无反应,解决ecshop清除缓存css样式没反应问题
- android控件---自定义带文本的ImageButton
- python编码解码的过程_使用Python过程中的编码和解码
- Java System类runFinalization()方法及示例
- 格式小结 css 0926
- Subversion快速入门教程(SVN)
- android q哪些手机型号,华为公布8款安卓Q首批升级机型
- php session 统计在线人数,利用文件属性结合session实现在线人数统计_php实例
- windows10防Linux,用户禁用Defender提升Win10 Linux子系统性能
- DELL RAID卡管理工具 MegaRAID Storage Manager(偏重RAID常用管理命令)
- OFDM-训练序列与导频
- c语言公路曲线要素,一、圆曲线要素及计算公式
- Python随记(27)bs4爬取豆瓣250
- 咖啡产品介绍PPT模板
- 2017-03-19第nn次考试
- 细雨湿衣看不见 闲花落地听无声
- Python 自动化教程(2) : Excel自动化:使用pandas库
- 《孩子快抓紧妈妈的手》--为地震遇难的孩子们而作
- 第一个输出程序 Console.WriteLine
- QMT vs Ptrade 速度对比 (一) 历史行情获取速度