當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Client.PostForm方法代碼示例

本文整理匯總了Golang中net/http.Client.PostForm方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.PostForm方法的具體用法?Golang Client.PostForm怎麽用?Golang Client.PostForm使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net/http.Client的用法示例。


在下文中一共展示了Client.PostForm方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: postReadLines

func (self *uniqushPush) postReadLines(path string, data url.Values, nrLines int) (value string, err error) {
	if len(path) == 0 {
		return
	}

	url := fmt.Sprintf("http://%v/%v", self.addr, path)

	c := http.Client{
		Transport: &http.Transport{
			Dial: timeoutDialler(self.timeout),
		},
	}
	resp, err := c.PostForm(url, data)
	if err != nil {
		return
	}
	defer resp.Body.Close()
	if nrLines > 0 {
		respBuf := bufio.NewReader(resp.Body)
		line := make([]byte, 0, nrLines*512)
		for i := 0; i < nrLines; i++ {
			l, _, e := respBuf.ReadLine()
			if e != nil {
				err = e
				return
			}
			line = append(line, l...)
		}
		value = string(line)
	}
	return
}
開發者ID:uniqush,項目名稱:uniqush-conn,代碼行數:32,代碼來源:push.go

示例2: main

func main() {
	text, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		os.Stderr.WriteString("Failed to read anything: " + err.Error() + "\n")
		os.Exit(1)
	}

	vals := make(url.Values)
	vals.Set("body", string(text))

	skipRedirect := errors.New("I want the Location")

	c := http.Client{
		CheckRedirect: func(req *http.Request, via []*http.Request) error {
			return skipRedirect
		},
	}

	resp, err := c.PostForm("http://itsapad.appspot.com", vals)
	if err != nil && err.(*url.Error).Err != skipRedirect {
		os.Stderr.WriteString("Request failed: " + err.Error() + "\n")
		os.Exit(1)
	}
	defer resp.Body.Close()

	loc, err := resp.Location()
	if err != nil {
		os.Stderr.WriteString("Response failed: " + err.Error() + "\n")
		os.Exit(1)
	}
	os.Stderr.WriteString(loc.String() + "\n")
}
開發者ID:mccoyst,項目名稱:topad,代碼行數:32,代碼來源:main.go

示例3: auth_user

func auth_user(email string, password string, client_id string, scope string, client *http.Client) (*http.Response, error) {
	var auth_url = "http://oauth.vk.com/oauth/authorize?" +
		"redirect_uri=http://oauth.vk.com/blank.html&response_type=token&" +
		"client_id=" + client_id + "&v=5.0&scope=" + scope + "&display=wap"

	res, e := client.Get(auth_url)
	if e != nil {
		return nil, e
	}

	doc, err := goquery.NewDocumentFromResponse(res)
	if err != nil {
		return nil, err
	}

	formData, url, err := parse_form(doc)
	if err != nil {
		return nil, err
	}
	formData.Add("email", email)
	formData.Add("pass", password)

	res, e = client.PostForm(url, formData)
	if e != nil {
		return nil, e
	}
	return res, nil
}
開發者ID:mantyr,項目名稱:vk_api,代碼行數:28,代碼來源:api.go

示例4: post

func post(pass string) (string, error) {
	mynil := ""
	certf, keyf, err := shared.ReadMyCert("client.crt", "client.key")
	if err != nil {
		return mynil, err
	}
	tlsConfig, err := shared.GetTLSConfig(certf, keyf)
	if err != nil {
		return mynil, err
	}

	//loadServerCert()
	uri := fmt.Sprintf("https://%s:%d/register", serverIp, serverPort)

	tr := &http.Transport{
		TLSClientConfig: tlsConfig,
		Proxy:           http.ProxyFromEnvironment,
	}
	hc := http.Client{Transport: tr}

	form := url.Values{}
	form.Add("password", pass)

	resp, err := hc.PostForm(uri, form)
	if err != nil {
		return mynil, err
	}
	defer resp.Body.Close()
	s, err := ioutil.ReadAll(resp.Body)
	val := fmt.Sprintf("%s", s)
	if err != nil {
		return mynil, err
	}
	return val, err
}
開發者ID:jsimonetti,項目名稱:tlstun,代碼行數:35,代碼來源:register.go

示例5: request

func (c *Client) request(client *http.Client, credentials *Credentials, urlStr string, params url.Values) (*Credentials, url.Values, error) {
	c.SignParam(credentials, "POST", urlStr, params)
	resp, err := client.PostForm(urlStr, params)
	if err != nil {
		return nil, nil, err
	}
	p, err := ioutil.ReadAll(resp.Body)
	resp.Body.Close()
	if err != nil {
		return nil, nil, err
	}
	if resp.StatusCode != 200 {
		return nil, nil, fmt.Errorf("OAuth server status %d, %s", resp.StatusCode, string(p))
	}
	vals, err := url.ParseQuery(string(p))
	if err != nil {
		return nil, nil, err
	}
	credentials = &Credentials{
		Token:  vals.Get("oauth_token"),
		Secret: vals.Get("oauth_token_secret"),
	}
	if credentials.Token == "" {
		return nil, nil, errors.New("No OAuth token in server result")
	}
	if credentials.Secret == "" {
		return nil, nil, errors.New("No OAuth secret in server result")
	}
	return credentials, vals, nil
}
開發者ID:freeformz,項目名稱:go-oauth,代碼行數:30,代碼來源:oauth.go

示例6: post

func (c *Client) post(uri string, values url.Values, seconds int) error {
	if c.Debug {
		fmt.Printf("Making request to to: %s\n", uri)
	}
	timeout := time.Duration(seconds) * time.Second
	dial := func(network, addr string) (net.Conn, error) {
		return net.DialTimeout(network, addr, timeout)
	}

	transport := http.Transport{Dial: dial}
	client := http.Client{Transport: &transport}

	response, err := client.PostForm(uri, values)
	if err != nil {
		return err
	}
	defer response.Body.Close()

	data, _ := ioutil.ReadAll(response.Body)

	if err := json.Unmarshal(data, &c.State); err != nil {
		return err
	}

	if c.Debug {
		fmt.Printf("Setting data to:\n%s\n", string(data))
	}

	return nil
}
開發者ID:jisaac01,項目名稱:vindinium-starter-go,代碼行數:30,代碼來源:client.go

示例7: request

func (c *V4Client) request(timeout time.Duration, params map[string]string) (PiplResponse, error) {
	req, _ := url.Parse(c.BaseURL)
	p := url.Values{}

	for k, v := range params {
		p.Add(k, v)
	}
	p.Add("key", c.ApiKey)

	// maybe move http client up into struct
	client := http.Client{
		Timeout: timeout,
	}
	response, err := client.PostForm(req.String(), p)
	person := PiplResponse{}

	if err != nil {
		return person, err
	} else {
		defer response.Body.Close()
		contents, err := ioutil.ReadAll(response.Body)
		if err != nil {
			return person, err
		}
		if err = json.Unmarshal(contents, &person); err != nil {
			return person, err
		}
		if len(person.Error) > 0 {
			return person, errors.New(person.Error)
		}
		return person, nil
	}
}
開發者ID:mike-marcacci,項目名稱:go-pipl,代碼行數:33,代碼來源:client.go

示例8: ClientLogin

func ClientLogin(client *http.Client, email, password, service string) (string, error) {
	resp, err := client.PostForm(clientLoginUrl, url.Values{
		"accountType": {"HOSTED_OR_GOOGLE"},
		"Email":       {email},
		"Passwd":      {password},
		"service":     {"lh2"},
	})
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()

	// check for 200

	r := bufio.NewReader(resp.Body)
	var auth string
	for {
		line := MustReadLine(r)
		if line == nil {
			break
		}

		parts := bytes.SplitN(line, []byte("="), 2)
		if len(parts) != 2 {
			log.Panicf("bad line %q", line)
		}
		if string(parts[0]) == "Auth" {
			auth = string(parts[1])
		}
	}

	return auth, nil
}
開發者ID:evmar,項目名稱:picasync,代碼行數:33,代碼來源:clientlogin.go

示例9: ClientPostForm

// Retry wrapper for http://golang.org/pkg/net/http/#Client.PostForm where attempts is the number of http calls made (one plus number of retries).
func (httpRetryClient *Client) ClientPostForm(c *http.Client, url string, data url.Values) (resp *http.Response, attempts int, err error) {
	return httpRetryClient.Retry(func() (*http.Response, error, error) {
		resp, err := c.PostForm(url, data)
		// assume all errors should result in a retry
		return resp, err, nil
	})
}
開發者ID:taskcluster,項目名稱:taskcluster-worker,代碼行數:8,代碼來源:httpbackoff.go

示例10: main

func main() {
	client := http.Client{}

	for {

		si := syscall.Sysinfo_t{}
		syscall.Sysinfo(&si)

		l := strconv.FormatFloat(float64(si.Loads[0])/65536, 'f', 2)
		fmt.Println(l, si.Loads[0]/65536.0, si.Loads[0])

		time.Sleep(1 * time.Second)
		continue

		resp, err := client.PostForm("https://api.stathat.com/ez", url.Values{
			"stat":  {"loadavg"},
			"ezkey": {"YLJRun7adtSFKR2u"},
			"value": {l},
		})
		if err != nil {
			// Problems...
			fmt.Println("Error sending stat... : %v", err)
			os.Exit(1)
		}
		fmt.Println(resp)
		resp.Body.Close()
		time.Sleep(1 * time.Second)
	}
}
開發者ID:marcelom,項目名稱:gocollector,代碼行數:29,代碼來源:collector.go

示例11: incomingImageHandler

func incomingImageHandler(w http.ResponseWriter, r *http.Request) error {
	c := appengine.NewContext(r)
	config := google.NewAppEngineConfig(c, "https://www.googleapis.com/auth/userinfo.email")
	config.Transport = &urlfetch.Transport{
		Context:                       c,
		Deadline:                      time.Minute,
		AllowInvalidServerCertificate: true,
	}
	client := http.Client{Transport: config.NewTransport()}

	r.ParseForm()
	res, err := client.PostForm(backendAddress, r.Form)
	if err != nil {
		return fmt.Errorf("backend: %v", err)
	}

	if res.StatusCode != http.StatusOK {
		b, err := httputil.DumpResponse(res, true)
		if err != nil {
			return fmt.Errorf("dump response: %v", err)
		}
		c.Errorf("backend failed with code %v:\n%s", res.Status, b)
	}

	w.WriteHeader(res.StatusCode)
	_, err = io.Copy(w, res.Body)
	return err
}
開發者ID:qwo,項目名稱:abelana-gcp,代碼行數:28,代碼來源:notice.go

示例12: post

func (c *Client) post(uri string, params map[string]string, timeout time.Duration) error {
	p := url.Values{}
	for key := range params {
		p.Set(key, params[key])
	}

	dialFunc := func(network, addr string) (net.Conn, error) {
		return net.DialTimeout(network, addr, timeout)
	}

	transport := http.Transport{Dial: dialFunc}
	client := http.Client{Transport: &transport}

	response, err := client.PostForm(uri, p)
	if err != nil {
		return err
	}
	defer response.Body.Close()

	data, err := ioutil.ReadAll(response.Body)
	if err != nil {
		return err
	}

	decoder := json.NewDecoder(bytes.NewReader(data))
	if err := decoder.Decode(&c.state); err != nil {
		return err
	}

	return nil
}
開發者ID:jbcrail,項目名稱:vindinium-starter-go,代碼行數:31,代碼來源:client.go

示例13: postRequest

//提交HTTP請求
func postRequest(callUrl string, method string, params map[string]string, protocol string) (map[string]interface{}, error) {
	var client *http.Client
	if strings.ToUpper(protocol) == "HTTPS" {
		tr := &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
		}
		client = &http.Client{Transport: tr}
	} else {
		client = &http.Client{}
	}

	urlvs := url.Values{}
	for k, v := range params {
		urlvs.Add(k, v)
	}
	resp, err := client.PostForm(callUrl, urlvs)
	if err != nil {
		//fmt.Println("error")
		return nil, err
	}
	defer resp.Body.Close()
	body, tmpErr := ioutil.ReadAll(resp.Body)
	if tmpErr != nil {
		return nil, tmpErr
	}
	result := make(map[string]interface{})
	json.Unmarshal([]byte(body), &result)
	return result, nil

}
開發者ID:jacky2007,項目名稱:openqq_sdk,代碼行數:31,代碼來源:openqq.go

示例14: validateCourseID

func validateCourseID(stuid string, courseContent CourseContent, client *http.Client) (flag bool) {
	grade := stuid[:2]
	major := "11" + stuid[2:6]
	res, err := client.PostForm(DHUHostUrl+DHUTeachSchemaUrl, MakeParameters(map[string]string{"gradeYear": grade, "majorId": major}))
	if err != nil {
		return
	}
	doc, err := goquery.NewDocumentFromResponse(res)
	if err != nil {
		return
	}
	doc.Find("tr").EachWithBreak(func(i int, s *goquery.Selection) bool {
		breaks := true
		element := s.Find("td").Eq(1).Text()
		element = strings.TrimSpace(element)
		_, err := strconv.Atoi(element)
		if err == nil {
			if courseContent.CourseID == element {
				breaks = false
				flag = true
			}
		}
		return breaks
	})
	return
}
開發者ID:XingLong9630,項目名稱:DHUCourseSelection,代碼行數:26,代碼來源:WebApi_test.go

示例15: HttpGetCookieJar

func HttpGetCookieJar(url string, callType string,
	config M) (*cookiejar.Jar, error) {

	var resp *http.Response
	var errCall error
	var client *http.Client

	jar, e := cookiejar.New(nil)
	if e != nil {
		return nil, fmt.Errorf("Unable to initialize cookie jar: %s", e.Error())
	}

	client = &http.Client{
		Jar: jar,
	}

	if callType == "POST" {
		if config.Has("loginvalues") {
			fvs := config["loginvalues"].(M)
			vs := httpurl.Values{}
			for k, v := range fvs {
				vs.Set(k, v.(string))
			}

			resp, errCall = client.PostForm(url, vs)
			if errCall == nil {
				resp.Body.Close()
			}
		}
	} else {
		_, errCall = client.Get(url)
	}

	return jar, errCall
}
開發者ID:rinosukmandityo,項目名稱:toolkit,代碼行數:35,代碼來源:http.go


注:本文中的net/http.Client.PostForm方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。