webassembly跨域访问
Posted henreash
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了webassembly跨域访问相关的知识,希望对你有一定的参考价值。
出现如下错误:
SEC7123: [CORS] 原点“https://localhost:44377”已阻止 preflight 请求,它的 Request Header “authorization”未出现在“http://localhost:12345/qry_pagition”的 cross-origin 请求的 Access-Control-Allow-Headers response header 列表中。
说明请求header中含有authorization,但服务端不允许这样的header内容,因此需要在服务端添加如下代码:
//允许跨域
w.Header().Set("Access-Control-Allow-Origin", "*");
w.Header().Set("Access-Control-Allow-Credentials", "true");
w.Header().Set("Access-Control-Allow-Methods", "*");
w.Header().Set("Access-Control-Allow-Headers", "Content-Type,Access-Token,authorization");
w.Header().Set("Access-Control-Expose-Headers", "*");
w.Header().Set("content-type", "application/json")
if r.Method == "OPTIONS"
w.WriteHeader(http.StatusOK);
return
h(w, r)
在Access-Control-Allow-Headers中包含authorization即可。
以上是关于webassembly跨域访问的主要内容,如果未能解决你的问题,请参考以下文章
Blazor解决Blazor WebAssembly跨域访问后台服务问题
Blazor解决Blazor WebAssembly跨域访问后台服务问题