Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Golang Wasm HTTP请求失败_Http_Go_Webassembly - Fatal编程技术网

Golang Wasm HTTP请求失败

Golang Wasm HTTP请求失败,http,go,webassembly,Http,Go,Webassembly,我有点被Golang wasm的请求卡住了。当我测试代码时,它在服务中工作得很好,但是当我尝试使用wasm在浏览器中运行它时,我得到了一个fetch failed错误。如果我从独立服务调用此代码,则此代码运行良好: go func(){ authURL:=”https://auth.home.rsmachiner.com/login" 类型loginstuct struct{ 用户名字符串`json:“用户名”` 密码字符串`json:“密码”` } fmt.Println(“按下登录按钮”)

我有点被Golang wasm的请求卡住了。当我测试代码时,它在服务中工作得很好,但是当我尝试使用wasm在浏览器中运行它时,我得到了一个fetch failed错误。如果我从独立服务调用此代码,则此代码运行良好:

go func(){
authURL:=”https://auth.home.rsmachiner.com/login"
类型loginstuct struct{
用户名字符串`json:“用户名”`
密码字符串`json:“密码”`
}
fmt.Println(“按下登录按钮”)
fmt.Printf(“获得登录:%v\n”,r.LoginBoxValue)
fmt.Printf(“获取密码:%v\n”,r.PasswordValue)
var登录登录指令
login.Username=r.LoginBoxValue
login.Password=r.PasswordValue
数据,err:=json.Marshal(&login)
如果错误!=零{
fmt.Println(错误)
}
fmt.Println(字符串(数据))
req,u:=http.NewRequest(“POST”、authURL、bytes.NewBuffer(数据))
客户端:=&http.client{}
resp,err:=client.Do(请求)
如果错误!=零{
fmt.Println(“响应错误”)
fmt.Println(错误)
返回
}
body,err:=ioutil.ReadAll(resp.body)
如果错误!=零{
fmt.Println(错误)
返回
}
格式打印(“正文:”)
格式打印项次(字符串(正文))
}()
这会引发以下错误:

Post "https://auth.home.rsmachiner.com/login": net/http: fetch() failed: Failed to fetch
当我从一个独立的客户端尝试它时,效果很好。服务器也允许CORS与

w.Header().Set(“访问控制允许原点”,“*”)

对于任何偶然发现这一点的人来说,它在浏览器中也能正常工作。问题在于HTML而不是代码。HTML正在重新加载页面,因此请求因被终止而失败