网站首页 文章专栏 腾讯云函数scf与API网关跨域
腾讯云函数scf与API网关跨域
创建于:2019-06-18 06:53:29 更新于:2024-04-27 11:51:46 羽瀚尘 5858
网站

使用scf时碰到跨域问题,要从服务端和浏览器端两方面解决问题

  1. 后端设置headers
 return {
        "isBase64Encoded": False,
        "statusCode": 200,
        "headers": {'Content-Type': 'application/json',
                     'Access-Control-Allow-Origin': '*'},
        "body": json.dumps({'html_content':html_content,
                            'msg':'ok',
                            'cos_return':cos_ret
                        })
    }
  1. 前端设置content-type
axios({
          method:"post",
          url:url,
          data:JSON.stringify(article),
          headers:{
              "content-type":"application/x-www-form-urlencoded; charset=utf-8"
          }
        })

看到还有其他的跨域方法: 下载免费 ModHeader Chrome 浏览器扩展 (或任何其他允许您修改 HTTP 响应标头的浏览器扩展)。 猜测是浏览器行为,无法让非开发者的用户使用