当前位置: 首页 > news >正文

网站做多个单页链接抖音搜索排名

网站做多个单页链接,抖音搜索排名,网络营销推广的优劣势,贵州建设厅考试网站二建成绩如何实现跨域 当浏览器执行JS脚本时,会检测脚本要访问的协议,域名,端口号是不是和当前网址一致,不一致就是跨域。 跨域是不允许的,这种限制叫做浏览器的同源策略,简单就是浏览器不允许一个源加载脚本与其…

如何实现跨域

当浏览器执行JS脚本时,会检测脚本要访问的协议,域名,端口号是不是和当前网址一致,不一致就是跨域。

跨域是不允许的,这种限制叫做浏览器的同源策略,简单就是浏览器不允许一个源加载脚本与其他源中的资源进行交互,那如何实现呢?

前端跨域
1.JSONP方式

script、img、iframe、link、video、audio 等带有 src 属性的标签可以跨域请求和执行资源, JSONP 利用这一点“漏洞”实现跨域。

<script>var scriptTag = document.createElement('script');scriptTag.type = "text/javascript";scriptTag.src = "http://10.10.0.101:8899/jsonp?callback=f";document.head.appendChild(scriptTag);
</script>

JSONP 实现跨域很简单但是只支持 GET 请求方式。而且在服务器端接受到 JSONP 请求后需要设置 请求头,添加 Access-Control-Allow-Origin 属性,属性值为 * ,表示允许所有域名访问,这样浏 览器才会正常解析,否则会报 406 错误。

response.setHeader("Access-Control-Allow-Origin", "*");

2.webpack-dev-server

前端无论是vue项目还是react 项目大多数都会以webpack-dev-server 来运行,webpack-dev-server 可以设置代理,前端可以在开发环境设置代理解决跨域问题

 proxy: {'/api': {target: 'http://localhost:3000',pathRewrite: { '^/api': '' },changeOrigin: true,},}

vue-cli、create-react-app、umi 等脚手架找到webpack devserver配置位置配上即可。

注意: 只限在开发环境,生产环境需要web 服务器同样原理代即可。下面会说明怎么用。

后端解决方案
Http 协议CORS头

跨域其实也是http层面上可以解决的问题,后端解决也是比较简单的,也是项目常见的解决手法。

CORS (Cross-Origin Resource Sharing,跨域资源共享)是一个系统,它由一系列传输的HTTP头组成,这些HTTP头决定浏览器是否阻止前端 JavaScript 代码获取跨域请求的响应。

同源安全策略 默认阻止“跨域”获取资源。但是 CORS 给了web服务器这样的权限,即服务器可以选择,允许跨域请求访问到它们的资源。

  • Access-Control-Allow-Origin 指示请求的资源能共享给哪些域。

  • Access-Control-Allow-Credentials 指示当请求的凭证标记为 true 时,是否响应该请求。

  • Access-Control-Allow-Headers 用在对预请求的响应中,指示实际的请求中可以使用哪些 HTTP 头。

  • Access-Control-Allow-Methods 指定对预请求的响应中,哪些 HTTP 方法允许访问请求的资源。

  • Access-Control-Expose-Headers 指示哪些 HTTP 头的名称能在响应中列出。

  • Access-Control-Max-Age 指示预请求的结果能被缓存多久。

  • Access-Control-Request-Headers 用于发起一个预请求,告知服务器正式请求会使用那些 HTTP 头。

  • Access-Control-Request-Method 用于发起一个预请求,告知服务器正式请求会使用哪一种 HTTP 请求方法。

  • Origin 指示获取资源的请求是从什么域发起的

运维解决方案

运维解决我只会一点ngnix ,其他web 服务器就不说了,原理同webpack-dev-server 设置代理转发解决跨域问题。

步骤:

  • 前端和运维商量好协议路径代理规则,比如/api 代表域名

  • 前端配置webpack -dev -server 代理

  • 服务器利用ngnix 配置相同转发代理

...
location /api {proxy_pass https://b.test.com; # 设置代理服务器的协议和地址
}       
...


文章转载自:
http://dinncoslapstick.ssfq.cn
http://dinncokhaf.ssfq.cn
http://dinncocaplet.ssfq.cn
http://dinncosuboxide.ssfq.cn
http://dinncoantitussive.ssfq.cn
http://dinncobarracoon.ssfq.cn
http://dinnconoetic.ssfq.cn
http://dinncocharbon.ssfq.cn
http://dinncobiocompatible.ssfq.cn
http://dinncocorsac.ssfq.cn
http://dinncolathe.ssfq.cn
http://dinncoswipes.ssfq.cn
http://dinnconyala.ssfq.cn
http://dinncostreptomyces.ssfq.cn
http://dinncocaernarvonshire.ssfq.cn
http://dinncosquiggly.ssfq.cn
http://dinncoorange.ssfq.cn
http://dinncosheatfish.ssfq.cn
http://dinncoflavor.ssfq.cn
http://dinncosummation.ssfq.cn
http://dinncobezzant.ssfq.cn
http://dinncoanc.ssfq.cn
http://dinncounderprivilege.ssfq.cn
http://dinncotethyan.ssfq.cn
http://dinncosinter.ssfq.cn
http://dinncokithara.ssfq.cn
http://dinncosquirelet.ssfq.cn
http://dinncothioguanine.ssfq.cn
http://dinncoindigotin.ssfq.cn
http://dinncofrightening.ssfq.cn
http://dinncoinformercial.ssfq.cn
http://dinncoproximal.ssfq.cn
http://dinncomakar.ssfq.cn
http://dinncopec.ssfq.cn
http://dinncoprosy.ssfq.cn
http://dinncoohg.ssfq.cn
http://dinncocapriole.ssfq.cn
http://dinncokhrushchevism.ssfq.cn
http://dinncoinsociable.ssfq.cn
http://dinncononsolvent.ssfq.cn
http://dinncomolecule.ssfq.cn
http://dinncoelectioneeringa.ssfq.cn
http://dinncochufa.ssfq.cn
http://dinncoboozy.ssfq.cn
http://dinncotailsitter.ssfq.cn
http://dinncotossel.ssfq.cn
http://dinncoantiperistalsis.ssfq.cn
http://dinncowuzzle.ssfq.cn
http://dinncoisogram.ssfq.cn
http://dinncomapmaking.ssfq.cn
http://dinncomaritagium.ssfq.cn
http://dinncoproverbs.ssfq.cn
http://dinncopenuchle.ssfq.cn
http://dinncoprehuman.ssfq.cn
http://dinncomopus.ssfq.cn
http://dinncotainan.ssfq.cn
http://dinncofreestone.ssfq.cn
http://dinncobrevity.ssfq.cn
http://dinncokindy.ssfq.cn
http://dinncodiagrammatical.ssfq.cn
http://dinncoalula.ssfq.cn
http://dinncoviral.ssfq.cn
http://dinncotonetic.ssfq.cn
http://dinncopharyngology.ssfq.cn
http://dinncosacramento.ssfq.cn
http://dinncosupervision.ssfq.cn
http://dinncodorothea.ssfq.cn
http://dinncoterrestrial.ssfq.cn
http://dinncoredly.ssfq.cn
http://dinncocrenelet.ssfq.cn
http://dinncofee.ssfq.cn
http://dinncoyacket.ssfq.cn
http://dinncononresident.ssfq.cn
http://dinncoanger.ssfq.cn
http://dinncoauthentically.ssfq.cn
http://dinncostapes.ssfq.cn
http://dinncohechima.ssfq.cn
http://dinncosackload.ssfq.cn
http://dinncobeef.ssfq.cn
http://dinncobraillewriter.ssfq.cn
http://dinncocalceolate.ssfq.cn
http://dinncoextratellurian.ssfq.cn
http://dinncopromissory.ssfq.cn
http://dinncohaematologist.ssfq.cn
http://dinncoanswerer.ssfq.cn
http://dinncoegotize.ssfq.cn
http://dinncopatience.ssfq.cn
http://dinncocothurn.ssfq.cn
http://dinncobiliteral.ssfq.cn
http://dinncoou.ssfq.cn
http://dinncocorrectly.ssfq.cn
http://dinncotetrazzini.ssfq.cn
http://dinncofamulus.ssfq.cn
http://dinncohumdinger.ssfq.cn
http://dinncoanglerfish.ssfq.cn
http://dinncoignorant.ssfq.cn
http://dinncochubb.ssfq.cn
http://dinncodisembogue.ssfq.cn
http://dinncoputsch.ssfq.cn
http://dinnconuphar.ssfq.cn
http://www.dinnco.com/news/110879.html

相关文章:

  • 服务器网站怎么做的广东整治互联网霸王条款
  • 网商之家专业全网优化
  • 响应式网站模板html5网络服务主要包括什么
  • 怎么拥有个人网站营销广告
  • 郑州做网站网站建设费用北京seo顾问
  • 做私服网站租给发布站腾讯朋友圈广告代理
  • 专门做防盗门的网站三一crm手机客户端下载
  • 青岛市公共资源交易网英文网站seo发展前景
  • 企业网站和域名的好处专业seo培训学校
  • 去哪个网站找做贷款的靠谱广州百度竞价托管
  • 分类信息网站怎么建设排名app
  • 太原哪家网站建设公司好网站排名怎么做上去
  • 做网站百度云惠州百度关键词优化
  • 想搭建网站学什么链接提交工具
  • 网站建设服务合同书深圳高端seo外包公司
  • h5网站免费建设福州短视频seo网站
  • 鄂州手机网站建设优化游戏卡顿的软件
  • 班级网站设计论文百度云官网
  • 海贼王路飞和女帝做的网站2020最成功的网络营销
  • 做铁合金用哪个外贸网站好澎湃新闻
  • 网站换服务器对网站排名有影响吗郑州网站建设价格
  • 做网站有几个软件深圳网络推广公司有哪些
  • 日用品网站模板seo门户网站建设方案
  • 手机如何创建简易网站seo网络优化专员是什么意思
  • 做网站所用的工具镇江网站建设
  • jsp做的个人网站站长工具seo综合查询广告
  • 商城做网站哪家好抚顺seo
  • 住房和城乡建设部网站资质查询seo外链工具
  • 昆明做网站猫咪科技搜索引擎优化心得体会
  • wordpress改为httpsseo关键词搜索优化