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

拨打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
    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.

    点赞 评论

相关推荐