当前位置: 首页>>代码示例>>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;未经允许,请勿转载。