Gopherjs: how to ignore https insecure verify

88 views
Skip to first unread message

Jun Wang

unread,
May 26, 2016, 5:05:44 PM5/26/16
to GopherJS
Hi everyone,

Recently, I want to use gopherjs to transfer my go code to js, but I got a problem of https post request.

In golang, first I wrote this:


func test() {
...
tr := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } client := &http.Client{Transport: tr} _, err := client.Post("https://golang.org/", "", reader) if err != nil { fmt.Println(err) }
... }

After transferred to js code, I got "Uncaught Error: network access is not supported by GopherJS". I think the problem is that I use the customized http client, and gopherjs not implemented this(I guess...)

Then I try to use the default client:

"func test() {
...
resp, err := http.Post("https://golang.org/",  "", reader)
... }

There is no more that uncaught error but a "net::ERR_INSECURE_RESPONE" which is not superseded.

My question is, is there a way to do a https post without insecure verification with gopherjs?

Thanks.

Best

wj






Dmitri Shuralyov

unread,
Jun 3, 2016, 4:32:07 AM6/3/16
to GopherJS
Is this something that's achievable using Web APIs?

It doesn't seem to be the case from what I can see (but I could be wrong, let me know if so).

If it were the case, it would be possible to accomplish it using Go/GopherJS as well. GohperJS simply lets you use Go to write the code, but you're still limited to what browsers allow JavaScript to do.

After transferred to js code, I got "Uncaught Error: network access is not supported by GopherJS". I think the problem is that I use the customized http client, and gopherjs not implemented this(I guess...)

Yes, the default Transport is not implemented. Default client in GopherJS is overridden to use either XHRTransport or fetchTransport, which are specific to GopherJS's implementation of net/http (see internal details here if you wish).

That means if you want to make your own client, you should do:

client := &http.Client{Transport: http.DefaultTransport}

Or, if you're okay with writing GopherJS-specific code (behind a build tag), then you can do &http.Client{Transport: &http.XHRTransport{}}.

Hope that helps.
Reply all
Reply to author
Forward
0 new messages