Exemplo n.º 1
0
func (wv *WebView) SetURLWithPost(url string, postData netUrl.Values) error {
	return wv.withWebBrowser2(func(webBrowser2 *win.IWebBrowser2) error {
		urlBstr := win.StringToVariantBSTR(url)
		flags := win.IntToVariantI4(0)
		targetFrameName := win.StringToVariantBSTR("_self")

		postStr := ""

		for k, v := range postData {
			if len(v) == 1 {
				postStr += k + "=" + netUrl.QueryEscape(v[0]) + "&"
			} else {
				for i, _v := range v {
					postStr += k + "[" + strconv.Itoa(i) + "]=" + netUrl.QueryEscape(_v) + "&"
				}
			}
		}

		postStr = postStr[:len(postStr)-1]

		postBstr := unsafe.Pointer(win.StringToVariantBSTR(postStr))

		if hr := webBrowser2.Navigate2(urlBstr, flags, targetFrameName, postBstr, nil); win.FAILED(hr) {
			return errorFromHRESULT("IWebBrowser2.Navigate2", hr)
		}

		return nil
	})
}
Exemplo n.º 2
0
func (wv *WebView) SetURL(url string) error {
	return wv.withWebBrowser2(func(webBrowser2 *win.IWebBrowser2) error {
		urlBstr := win.StringToVariantBSTR(url)
		flags := win.IntToVariantI4(0)
		targetFrameName := win.StringToVariantBSTR("_self")

		if hr := webBrowser2.Navigate2(urlBstr, flags, targetFrameName, nil, nil); win.FAILED(hr) {
			return errorFromHRESULT("IWebBrowser2.Navigate2", hr)
		}

		return nil
	})
}