c# 跨域api
前端 ajax get请求
 $.ajax({
            url: "API地址",
            type: 'get',
            dataType: 'jsonp',
            async: true,
            processData: true,
            contentType: false,
            success: function (res) {
                console.log(res)
            },
            error: function (Error) {
                console.log(Error)
            }
        })
前端 ajax post请求
$.ajax({
            type: 'post',
            url: 'API地址',
            data: data,
            dataType: "json",
            crossDomain: true,
            success: function (data) {
                console.log(data);
            },
            error: function (data) {
                console.log(data);
            }
        });
c# 后端 get请求
var res="最好转换成json";
string callback = this.Request["callback"];
return Content(callback + "(" + res + ")");
c# 后端 post 请求
//1.可以创建一个FilterAttribute
public class PostAPIController : ActionFilterAttribute
{
//override OnActionExecuting
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//设置
filterContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
filterContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Methods", "POST");
filterContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Headers", "x-requested-with,content-type"); base.OnActionExecuting(filterContext);
}
}
//2.post请求代码块 加上过滤器 PostAPIController
[HttpPost]
[PostAPIController]
public ActionResult AddReadNum(int newid)
{
try
{
*******
*******
if (string.IsNullOrEmpty(callback))
{
return Json(result, JsonRequestBehavior.AllowGet);
}
else
{
string res = JsonToots.ModelToJson(result);
return Content(callback + "(" + res + ")"); } }
catch (Exception ex)
{
******
}
}
c# 跨域api的更多相关文章
- 跨域API
		跨域API 简单跨域请求 只需要简单的设置允许跨域就可以了 def set_default_headers(self): self.set_header('Access-Control-Allow-O ... 
- MVC跨域API
		API using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Ne ... 
- php跨域请求
		跨域api服务器设置 header('content-type:application:json;charset=utf8'); header('Access-Control-Allow-Origin ... 
- Ajax跨域问题
		为了数据安全,默认情况下ajax请求是不支持跨域访问. 但是可以通过以下方法让ajax接收跨域API地址 第一种:JSONP比较老,较简单的请求可以考虑使用. JS代码 $(function () { ... 
- 【Vue+Node】解决axois请求数据跨域问题
		项目基于Vue前端+Node后台,启动两个服务,请求数据时,端口不一致造成跨域报错: (No 'Access-Control-Allow-Origin' header is present on th ... 
- Vue使用vue-recoure + http-proxy-middleware + vuex配合promise实现基本的跨域请求封装
		使用vue init webpack 你的项目名称初始化一个vue的项目 安装依赖 npm install vue-resource http-proxy-middleware vuex koa 在项 ... 
- 原创:【ajax | axios跨域简单请求+复杂请求】自定义header头Token请求Laravel5后台【亲测可用】
		如标题:我想在ajax的header头增加自定义Token进行跨域api认证并调用,api使用laravel5编写,如何实现? 首先,了解下CORS简单请求和复杂请求. -- CORS简单请求 -- ... 
- springboot+vue2.x 解决session跨域失效问题
		服务端SpringBoot2.x :localhost:8082 前端Vue2.x :localhost:81 前后端的端口号不同,为跨域,导致前端访问后端时,每次 ... 
- uni-app运行到浏览器跨域H5页面的跨域问题解决方案
		官方文档对跨域的解决方案推荐: https://ask.dcloud.net.cn/article/35267 更方便的解决方案 项目根目录直接创建一个vue.config.js文件,并在里面配置代理 ... 
随机推荐
- Android-Java-死锁
			死锁:程序不往下执行了,程序又没有结束,就一直卡在哪里: 在使用synchronized的时候要避免死锁,synchronized嵌套就可能会引发死锁,需要严格的检查代码,排除死锁发生的可能: 特意演 ... 
- Ubuntu 安装Sqldeveloper
			linux下最好用的Oracle开发工具可能就是sqldeveloper了 首先在http://otn.oracle.com/ 上下载最新的Linux - sqldeveloper 我下载的时候版本是 ... 
- mysql 多个and的简写
			select * from test where name='zj' and sex='2'; 我以前也经常用这种写法,今天爬出去看了一下某位人写的,用了一下也挺好用的 下面这种写法,一一对应关系 
- jenkins构建时报错
			配置好项目后,选择立即构建,报错 由于节点管理配置的太低,或者在节点的用法上 选择了不同的方式 解决办法: 1.尽可能的使用这个节点 2.保证配置过程没有错误. 
- [Word]让字符重合显示
			某些时候需要让字符重合显示,比如您好二字,显示为: 需要用到word的Advance域,他可以让后面的文字上下左右移动一定的磅. 譬如上面你好的显示:word中域代码为: 意思是好字向left移动了2 ... 
- 【转】AngularJs HTTP请求响应拦截器
			任何时候,如果我们想要为请求添加全局功能,例如身份认证.错误处理等,在请求发送给服务器之前或服务器返回时对其进行拦截,是比较好的实现手段. angularJs通过拦截器提供了一个从全局层面进行处理的途 ... 
- 常用Java集合类总结
			此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 7.1.List(允许重复元素) ArrayList: 底层数据结构:Object[] 在查询(get).遍 ... 
- XGBoost,GBDT原理详解,与lightgbm比较
			xgb原理: https://www.jianshu.com/p/7467e616f227 https://blog.csdn.net/a819825294/article/details/51206 ... 
- 在window主机上访问virtualbox虚拟机上centos7的tomcat服务
			在virtualbox上装完centos7后,随后装了tomcat服务器,然后在主机上发现用google浏览器访问tomcat不了 于是用ping检测下,发现ping不通,经过多方查找,才配置好,于是 ... 
- soap注入某sql2008服务器结合msf进行提权
			原文作者:陈小兵 在实际成功渗透过程中,漏洞的利用都是多个技术的融合,最新技术的实践,本次渗透利用sqlmap来确认注入点,通过sqlmap来获取webshell,结合msf来进行ms16-075的提 ... 
