// DefaultPostForm returns the specified key from a POST urlencoded form or multipart form
// when it exists, otherwise it returns the specified defaultValue string.
// See: PostForm() and GetPostForm() for further information.
546141
func (c *Context) DefaultPostForm(key, defaultValue string) string {
	if value, ok := c.GetPostForm(key); ok {
		return value
	}
	return defaultValue
}
1177562
func keyFromForm(param string) keyExtractor {
	return func(c echo.Context) (string, error) {
		key := c.FormValue(param)
		if key == "" {
			return "", errors.New("missing key in the form")
		}
		return key, nil
	}
}
714690
func NewForm(identifier FormIdentifier) *Form {
	if identifier == nil {
		panic("identifier func can't be nil")
	}

	return &Form{
		CookieName: "_u",
		CookiePath: "/",
		DefaultURL: "/",
		Identifier: identifier,
	}
}
998660
func (c *HTTPClient) PostForm(url string, data url.Values) (*http.Response, error) {
	panic("Use Do")
}
876474
func (f *Forms) Uint64(key string) (uint64, error) {
	return strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 64)
}
591159
func (c *Context) PostFormMap(key string) map[string]string {
	dicts, _ := c.GetPostFormMap(key)
	return dicts
}
168307
func Post(urlStr string, params map[string]interface{}) (*HttpResponse, error) {
	resp, err := DefaultClient.PostForm(urlStr, URLWithParams(urlStr, params).Query())
	if err == nil {
		return &HttpResponse{*resp}, nil
	} else {
		CloseResponse(resp)
		return nil, err
	}
}
49348
func (c *EzClient) PostFile(url, filepath, formName string, params map[string]string) (int, error) {
	// Setup body
	body := bytes.NewBufferString("")
	writer := multipart.NewWriter(body)
	defer writer.Close()

	// Create file form
	part, err := writer.CreateFormFile(formName, filepath)
	if err != nil {
		return 0, err
	}

	// Read file into form
	file, err := os.Open(filepath)
	if err != nil {
		return 0, err
	}
	defer file.Close()

	fileContents, err := ioutil.ReadAll(file)
	part.Write(fileContents)

	// Add boundary
	boundary := writer.Boundary()
	closeStr := fmt.Sprintf("\r\n--%s--\r\n", boundary)

	// Add additional params
	if params != nil {
		for key, value := range params {
			writer.WriteField(key, value)
		}
	}

	// Create the request and set headers
	closeBuf := bytes.NewBufferString(closeStr)
	reader := io.MultiReader(body, file, closeBuf)
	req, err := http.NewRequest("POST", url, reader)
	req.Header.Add("Content-Type", "multipart/form-data; boundary="+boundary)
	req.ContentLength = int64(body.Len()) + int64(closeBuf.Len())
	req.Close = true

	// Post the file
	resp, err := c.Client.Do(req)
	defer resp.Body.Close()
	b, _ := ioutil.ReadAll(resp.Body)

	// Return status and any error code
	if resp.StatusCode > 299 {
		return resp.StatusCode, errors.New(string(b))
	}

	return resp.StatusCode, nil
}
371322
func (f *Forms) Uint(key string) (uint, error) {
	v, err := strconv.ParseUint((*http.Request)(f).FormValue(key), 10, 64)
	return uint(v), err
}
830080
func (req *Request) GetMultipartForm() (ServerMultipartForm, error) {
	if form, err := req.In.Get(HTTP_MULTIPART_FORM); err != nil {
		return nil, err
	} else if values, found := form.(ServerMultipartForm); found {
		return values, nil
	}
	return nil, FORM_NOT_FOUND
}
107203
func (bow *Browser) PostForm(u string, data url.Values) error {
	return bow.Post(u, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
}
1076604
func PostURL(source, post string) ([]byte, error) {
	resp, err := http.Post(source, "application/octet-stream", strings.NewReader(post))
	if err != nil {
		return nil, fmt.Errorf("http post %s: %v", source, err)
	}
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("server response: %s", resp.Status)
	}
	defer resp.Body.Close()
	return ioutil.ReadAll(resp.Body)
}
1041202
func ParseFromForm(req *http.Request, format Format, u ...json.Unmarshaler) (JWS, error) {
	if b, ok := fromForm(req); ok {
		return parseJumpTable[format](b, u...)
	}
	return nil, ErrNoTokenInRequest
}
293167
func (wc *WebhookContext) Form() uurl.Values {
	//todo: bug, RAW() unavailable after ParseForm()
	wc.gin.Request.ParseForm()
	return wc.gin.Request.PostForm
}
316614
func serializeForm(sel *goquery.Selection) (url.Values, url.Values, url.Values, selects, FileSet) {
	fields := make(url.Values)
	buttons := make(url.Values)
	checkboxs := make(url.Values)
	selects := make(selects)
	files := make(FileSet)
	sel.Find("input,button,textarea").Each(func(_ int, s *goquery.Selection) {
		if v, ok := s.Attr("disabled"); ok && strings.ToLower(v) == "disabled" {
			return
		}
		if name, ok := s.Attr("name"); ok {
			val, _ := s.Attr("value")
			t, _ := s.Attr("type")
			t = strings.ToLower(t)
			if t == "submit" {
				buttons.Add(name, val)
			} else if t == "checkbox" || t == "radio" {
				if c, found := s.Attr("checked"); found && strings.ToLower(c) == "checked" {
					fields.Add(name, val)
				}
				if t == "checkbox" {
					checkboxs.Add(name, val)
				}
			} else if t == "file" {
				files[name] = &File{}
			} else {
				fields.Add(name, val)
			}
		}
	})

	sel.Find("select").Each(func(_ int, s *goquery.Selection) {
		if v, ok := s.Attr("disabled"); ok && strings.ToLower(v) == "disabled" {
			return
		}
		if name, ok := s.Attr("name"); ok {
			_, multiple := s.Attr("multiple")
			selects[name] = selectOptions{
				multiple: multiple,
				values:   make(url.Values),
				labels:   make(url.Values),
			}
			var foundSelected bool
			s.Find(`option`).Each(func(_ int, ss *goquery.Selection) {
				val, _ := ss.Attr("value")
				l, _ := ss.Html()
				selects[name].values.Add(val, strings.TrimSpace(html.UnescapeString(l)))
				selects[name].labels.Add(strings.TrimSpace(html.UnescapeString(l)), val)
				if foundSelected {
					return
				}
				sel, ok := ss.Attr("selected")
				if !ok {
					return
				}
				if sel != "" && strings.ToLower(sel) != "selected" {
					return
				}
				fields.Add(name, val)
				if multiple {
					return
				}
				foundSelected = true
			})
		}
	})

	return fields, buttons, checkboxs, selects, files
}
2068
func reqForm(r Request, params map[string]string, method string) (Request, error) {
	body := &bytes.Buffer{}
	writer := multipart.NewWriter(body)
	for key, val := range params {
		_ = writer.WriteField(key, val)
	}
	defer writer.Close()
	req, err := http.NewRequest(method, r.URI, body)
	req.Header.Add("Content-Type", writer.FormDataContentType())
	if r.Headers != nil {
		for _, header := range r.Headers {
			req.Header.Add(header.Key, header.Value)
		}
	}
	if r.BasicAuth.Username != "" {
		r.Req.SetBasicAuth(r.BasicAuth.Username, r.BasicAuth.Password)
	}
	r.Req = req
	return r, err
}
55600
func (d *DNSProvider) postRequest(cmd string, data url.Values) (*response, error) {
	uri := d.config.BaseURL + cmd

	if d.config.AuthSid != "" {
		data.Set("auth-sid", d.config.AuthSid)
	}

	if d.config.Debug {
		log.Infof("postRequest:\n\tURL: %q\n\tData: %v", uri, data)
	}

	resp, err := d.config.HTTPClient.PostForm(uri, data)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

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

	if resp.StatusCode != 200 {
		return nil, fmt.Errorf("HTTP error %d [%s]: %v", resp.StatusCode, http.StatusText(resp.StatusCode), string(body))
	}

	return parseResponse(string(body)), nil
}