有同学在使用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. AI图谱

  2. 江西财经大学第一届程序设计竞赛 H题 求大数的阶乘

    链接:https://www.nowcoder.com/acm/contest/115/H 来源:牛客网 晚上,小P喜欢在寝室里一个个静静的学习或者思考,享受自由自在的单身生活. 他总是能从所学的知识 ...

  3. PAT1135(红黑书的判定)

    There is a kind of balanced binary search tree named red-black tree in the data structure. It has th ...

  4. Codeforces Round #520 (Div. 2)

    Codeforces Round #520 (Div. 2) https://codeforces.com/contest/1062 A #include<bits/stdc++.h> u ...

  5. 【python】入门指南1

    基础的数据结构:int, float, string 注意:python入门系列的文章的示例均使用python3来完成. #!/bin/python a = 1 b = 1.0 c = 'string ...

  6. python的定时任务模块--schedule

    首先先安装一下模块 下面我们简单的学习一下schedule模块 先简单的看个示例 import schedule def test(*args,**kwargs): print("hello ...

  7. swift - 解析三方 - ObjectMapper

    // // JYQueryBespeakModel.swift // rtb // // Created by chen on 2018/3/30 // 查询预约信息 import UIKit imp ...

  8. 免费证书https://lamp.sh/ssl.html

    https(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的 http 通道,简单讲是 http 的安全版.即 ht ...

  9. 让 div中的div垂直居中的方法!!同样是抄袭来的(*^__^*)

    同样 ,水平居中很简单,给子div设置margin:0px auto; 垂直居中也不难::给父div设置display:table-cell;vertical-align:middle; 重点是dis ...

  10. Oracle_高级功能(1) 数据库设计

    1.三范式规范化关系模式称为范式.第一范式:在一个关系模型R中,如果R的每一个属性的值域中的值都是不可再分的最小数据单位, 则称R为第一范式(1NF).第二范式:如果一个关系模型R属于1NF,并且R的 ...