dongsuo9982 2019-04-27 13:12
浏览 53
已采纳

拨打tcp:协议不可用,请进行网络组装测试

Attempting to go test a web-assembly function which fires an POST request.

Receive the following error:

firePing_test.go:40: ERROR ON POST REQUEST: Post https://not-the-real-api.execute-api.us-east-1.amazonaws.com/testing: dial tcp: Protocol not available

Running: Ubuntu 18.04.2 LTS go version go1.12.2 linux/amd64

I've tested that the function is valid and will send a request when executing in chrome. Test also passes when compiled for linux/amd64.

Problem Function:

// FirePing fires a ping
func FirePing(protocol *string, domain *string, params *map[string]string) (*http.Response, error) {

    // Marshal map into POST request body
    reqBody, err := json.Marshal(*params)
    if err != nil {
        return  nil, fmt.Errorf("ERROR ON MARSHAL OF PARAMS: %v", err)
    }

    // Send POST request
    req, err := http.NewRequest("POST", *protocol + "://" + *domain, bytes.NewBuffer(reqBody))
    if err != nil {
        return  nil, fmt.Errorf("ERROR ON FORMING REQUEST: %v", err)
    }
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        return nil,fmt.Errorf("ERROR ON POST REQUEST: %v",err)
    }

    return resp, nil
}

Problem Test Function Call:

// FirePing and receive response
    resp, err := FirePing(&config.Config.Protocol, &config.Config.Domain, &m)
    if err != nil {
        t.Error(err)
        return
    }

Should pass this test case as it performs the function call fine in the browser.

Only other place I have seen this is:

http.Get returns Protocol not available error

Which seams to be from playground disabling tcp connections. I am running this test locally

  • 写回答

1条回答 默认 最新

  • douchun1948 2019-04-27 15:40
    关注

    The MVP release was exclusively targeting running WASM in the browser. As such, the browser APIs do not allow arbitrary TCP/IP connections and therefore WASM is equally limited. That said, WASM has always had ambitions to go beyond the browser. The latest initiative called WASI will add features required to be used outside the browser, like File I/O and networking primitives.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100