有同学在使用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. c++中的类(class)-----笔记(类继承)

    1,派生类继承了基类的所有成员函数和数据成员(构造函数.析构函数和操作符重载函数外). 2,当不指明继承方式时,默认为私有继承. 3,基类的私有成员仅在基类中可见,在派生类中是不可见的.基类的私有成员 ...

  2. 原生js,通过document.getElementByClassName获取元素的索引值

    let itemList = document.getElementsByClassName('sky-item') // 一行所有元素 let index = 0 for(let i = 0; i& ...

  3. Gym - 100989G 二分

    链接:ECJTU 2018 Summer Training 1 - Virtual Judge  https://vjudge.net/contest/236677#problem/G 谷歌翻译: 距 ...

  4. 188. Best Time to Buy and Sell Stock IV (Array; DP)

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  5. Shell教程 之字符串

    1.Shell字符串 字符串是shell编程中最常用最有用的数据类型(除了数字和字符串,也没啥其它类型好用了),字符串可以用单引号,也可以用双引号,也可以不用引号. 1.1 单引号 str='I am ...

  6. angular实现链接锚记

    前言: 之所以这么说,是因为angular的路由将html默认的链接锚记的#给占用了,所以传统的链接锚记在这里将不再适用,这个有点坑啊,又要多写好几行代码来模拟这个功能. 实现原理: location ...

  7. c#: PointToClient与PointToScreen

    起因: 很早就见过这两个方法,却未曾深入研究,偶尔一用,却纠结于其转换方法,遂写Demo以求验证,记录认知以做备忘. 其为Control类的内置方法,原型为: // // 摘要: // 将指定屏幕点的 ...

  8. 《centos系列》配置vim编辑器

    直接wget到~/目录下: wget  http://files.cnblogs.com/ma6174/vimrc.zip 然后进行解压: unzip  -f  vimrc.zip  -d  ~/ 参 ...

  9. 解决com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭

    com.microsoft.sqlserver.jdbc.SQLServerException: 该连接已关闭. at com.microsoft.sqlserver.jdbc.SQLServerEx ...

  10. mysql 5.6 datetime 保存精确到秒

    mysql中的CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP 设置默认值 now(3)  datetime 长度  3   保存精确到秒