有同学在使用kbmmw 与extjs 结合的时候,涉及到了跨域访问,这个在

kbmmw 里面已经完全解决。

extjs 在访问跨域的时候,首先会使用OPIONS  调用,服务端要根据浏览器请求的

head 来回应客户端,如果正确,则客户端再调用GET 方式访问服务器。

像不像我们地下党接头一样,首先要对一下暗号,暗号正确,开始交出城防图,不正确,对不起,开枪!

服务器端的代码,kbmmw 已经替大家处理了,很简单,只是设置允许访问的信息。

 [kbmMW_Method]
[kbmMW_Rest('method:get, path: "itemlist/{query}"')]
function GetItemlist([kbmMW_Rest('value: "{query}"')] const aQuery:string;
[kbmMW_Rest('value: "$ph", required: true')] const ph:string;
[kbmMW_Rest('value: "$pm", required: true')] const pm:string;
[kbmMW_Rest('value: "$xh", required: true')] const xh:string;
[kbmMW_Rest('value: "$gg", required: true')] const gg:string;
[kbmMW_Rest('value: "$th", required: true')] const th:string;
[kbmMW_Rest('value: "$jbm", required: true')] const jbm:string;
[kbmMW_Rest('value: "$gc", required: true')] const gc:string;
[kbmMW_Rest('value: "$limit", required: true')] const pagesize:string;
[kbmMW_Rest('value: "$page", required: true')] const pageindex:string;
[kbmMW_Rest('value: "$callback", required: true')] const callback:string):string;
end; implementation uses kbmMWExceptions, Unit1; {$R *.dfm} { TdgwRestService } function TdgwRestService.GetItemlist(const aQuery, ph, pm, xh, gg, th, jbm,
gc,pagesize, pageindex,callback: string): string;
begin
ProcessCORSRequest;
result := '{"result":"1","sumcount":1,"data":[{"PH":"ph001","PM":"pm001","XH":"xh001"},'
+ '{"PH":"ph002","PM":"pm002","XH":"xh002"}]}';
if callback<>'' then
Result:= callback + '(' + Result + ');'; end; procedure TdgwRestService.kbmMWCustomHTTPSmartServiceCORS(Sender: TObject;
const ARequestHelper, AResponseHelper: TkbmMWHTTPTransportStreamHelper;
const AOrigin: string; var AAllowedOrigins, AAllowedMethods,
AAllowedHeaders: string);
begin
AAllowedMethods:='GET' ;
AAllowedOrigins:='http://127.0.0.1';
AAllowedHeaders:= 'x-requested-with'; end;

运行截图

网站的源地址是http://127.0.0.1

跨域访问的地址是http://127.0.0.1:81

下面一图顶万言。

还是很简单的。

kbmmw 的HTTPSmartService中的跨域访问的更多相关文章

  1. 在IE浏览器中iframe跨域访问cookie/session丢失的解决办法

    单点登录需要在需要进入的子系统B中添加一个类,用于接收A系统传过来的参数: @Action(value = "outerLogin", results = { @Result(na ...

  2. asp.net中WebResponse 跨域访问示例

    前两天,一个朋友让我帮他写这样一个程序:在asp.net里面访问asp的页面,把数据提交对方的数据库后,根据返回的值(返回值为:OK或ERROR),如果为OK再把填入本地数据库.当时,想当然,觉得很简 ...

  3. WEX5中ajax跨域访问的几种方式

    1.使用jsonp方式 使用jsonp访问的话,前端需要把回调函数名传递给后端,后端执行完后也需要把回调函数传回给前端,默认情况下ajax自动生成一个回调函数名,后端可以通过String callba ...

  4. 【原创】Vue.js 中 axios 跨域访问错误

    1.假如访问的接口地址为 http://www.test.com/apis/index.php  (php api 接口) 2.而开发地址为http://127.0.0.1:8080,当axios发起 ...

  5. .NET中CORS跨域访问WebApi

    我这里只写基本用法以作记录,具体为什么看下面的文章: http://www.cnblogs.com/landeanfen/p/5177176.html http://www.cnblogs.com/m ...

  6. Asp.Net MVC 中实现跨域访问

    在ASP.Net webapi中可以使用  Microsoft.AspNet.WebApi.Cors  来实现: public static class WebApiConfig { public s ...

  7. web api中允许跨域访问

    ①添加owin的引用 ②添加owin.Cors的引用 ③在WebApiConfig中添加 config.EnableCors(new EnableCorsAttribute("*" ...

  8. IE中iframe跨域访问

    http://blog.csdn.net/ghsau/article/details/13747943

  9. 在Firefox中通过AJAX跨域访问Web资源---

    一.解决在firefox中无法跨域访问的问题 AJAX从本质上讲就是命名用XMLHttpRequest组件来向服务端发送HTTP请求,请接收相应信息.至于成功接收到响应信息后的操作,就和普通的Web客 ...

随机推荐

  1. K-邻近算法简单例子

    from numpy import * import operator import matplotlib.pyplot as plt def creatDataset(): group = arra ...

  2. Centos7在虚拟机中扩展磁盘空间

    说明 情况:已经在VirtualBox虚拟机创建了一个磁盘并已经装好了系统,发现磁盘空间太小,需要再添加一个磁盘的大小.或者说Centos7系统需要扩展磁盘空间. 步骤 1.VirtualBox新建磁 ...

  3. 1. Two Sum (快速排序;有序数组的查找: 两个指针; 哈希表)

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  4. 修改django后台用户名和密码

    cd到manage.py目录下 python manage.py shell >>from django.contrib.auth.models import User >>u ...

  5. 问题1:设置了text-overflow : ellipsis未起作用

    <style type="text/css"> * { padding: 0; } .div01 , .div02 { margin-top: 10px; border ...

  6. cocoapods 更新本地仓库 pod setup/update 无限远程中断

    升级 cocoapods 无限远程中断:网络不好 试了很多解决方法: 1.替换源,2.设置下载速度,3.清空本地master仓库,4.删了本地的pod库,5.半夜3-5点更新,6.按照失败提示的 (p ...

  7. java 线程Thread 技术--线程方法详解

    Thread 类常用的方法与Object类提供的线程操作方法:(一个对象只有一把锁

  8. linux 备忘录

    1. ps aux|grep 程序 -------->查看当前程序是否运行 ps aux|grep nginx 2. tar -zxvf 压缩包 ---------> 解压缩 tar -z ...

  9. 各个JSON技术的比较(Jackson,Gson,Fastjson)的对比

    JSON技术的调研报告 一 .各个JSON技术的简介和优劣 1.json-lib json-lib最开始的也是应用最广泛的json解析工具,json-lib 不好的地方确实是依赖于很多第三方包, 包括 ...

  10. 9.28 h5日记

    9.28 1.transparent 透明的 颜色 2.placeholder 提示语 在input中使用 跟velue不同 3.写页面需要注意的 (1)页面一定要有层次,分清层次 (2)保证元素模块 ...