MVC跨域访问ashx接口
来源:互联网 发布:开淘宝店图片 编辑:程序博客网 时间:2024/06/03 03:17
简介
对于webservice接口跨越访问有前端已有相关解决方案:比如:ajax使用jsonp 或者用专门的jquery.jsonp.js来进行访问。
此处介绍如何通过后台访问接口,然后将返回值提供给前台,此处以MVC编写为例
后台Control中编写
//url是要访问的服务接口地址 public string queryRespose(string url) { string json; try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Timeout = 15000; request.Method = "GET"; request.ContentType = "application/x-www-form-urlencoded"; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8); json = reader.ReadToEnd(); reader.Close(); } catch (Exception ex) { json = ex.Message; } return json; }
前端页面调用
$.ajax({ type: "GET", url: "/ControlName/queryRespose", dataType: "json", async: false, data: { url: url }, beforeSend: function () { }, success: lang.hitch(this, function (msg) { //dosomething }), error: function () { console.log("error"); }});
阅读全文
0 0
- MVC跨域访问ashx接口
- jquery跨域访问ashx
- 关于ASP.NET MVC WebApi接口跨域访问的解决方案
- 【.Net码农】使用ashx解决ajax跨域访问的问题
- Ajax跨域访问MVC
- ashx 访问 session
- AJAX 跨域请求 ashx
- jeesite跨域访问接口
- RestTemplate访问Spring MVC restFul接口
- iOS 如何调用ashx接口
- asp.net ashx访问session
- jquery访问ashx文件示例
- 关于Spring MVC 跨域访问
- ajax请求ashx跨域问题解决办法
- 当你希望从ashx或HttpHandler里访问你的Session时,你必须实现IReadOnlySessionState接口.
- ajax跨域访问数据接口 php
- js跨域访问接口(springmvc)
- springmvc实现jsonp跨域接口访问
- Java进阶(三)多线程开发关键技术
- 代码重构的必要性
- 弹性盒(Flexbox)和样式
- [php_06]PHP之session与cookie
- 内存对齐,导致char型数组指针转化为float型指针出现的问题
- MVC跨域访问ashx接口
- PHP 编程中 10 个最常见的错误,你犯过几个?
- 适配器模式2
- winsock编程
- 零基础学软件测试V2.0
- [动态最小生成树 CDQ分治] SnackDown 2017 Online Elimination Round #GQUERY Game Revisited
- vim复制粘贴
- informatica 遇到ORA-26002
- 【已解决】cannot invoke setopt()