zoukankan      html  css  js  c++  java
  • CORS跨域限制以及预请求验证

    cors包含的限制:

      默认允许方法:

        GET、HEAD、POST

      默认允许的Content-Type

        text/plain、multipart/form-data、application/x-www-form-urlencoded

        这三个也就是html的form表单可以设置的数据类型

      请求头的限制

        哪些请求头被限制哪些是默认允许的可以参考:

        https://fetch.spec.whatwg.org/#cors-safelisted-request-header

      XMLHttpRequestUpload对象均没有注册任何事件监听器

      请求中没有使用ReadableStream对象

    预请求验证:

    const http = require('http')
    
    http.createServer((req, res) => {
      console.log('request come', req.url)
    
      res.writeHead(200, {
        'Access-Control-Allow-Origin': '*',   // 允许访问我这个服务的网址
        'Access-Control-Allow-Header': 'X-Test-Cors', // 允许访问我这个服务的头
        'Access-Control-Allow-Methods': 'POST, PUT, Delete', // 允许访问我这个服务的方法
        'Access-Control-Max-Age': '1000'  // 多长时间内不需要再次发送预请求
      })
      res.end('123')
    }).listen(8887)
    
    console.log('server listening on 8887')
  • 相关阅读:
    POJ 1061
    hihocoder 1330
    HDU 1525
    UVALive 3938
    POJ 2528
    HDU 1754
    《ACM-ICPC程序设计系列 数论及其应用》例题个人答案记录
    URAL 1277
    HDU 3746
    HDU 2087
  • 原文地址:https://www.cnblogs.com/ladybug7/p/12334630.html
Copyright © 2011-2022 走看看