// SendRequest verifies, constructs, and authorizes an HTTP request.
SendRequest verifies, constructs, and authorizes an HTTP request.
// SendRequest verifies constructs and authorizes an HTTP request .
func (c *Client) SendRequest(method string, rawURL string, data url.Values,
	headers map[string]interface{}) (*http.Response, error) {
	u, err := url.Parse(rawURL)
	if err != nil {
		return nil, err
	}
	valueReader := &strings.Reader{}
	goVersion := runtime.Version()
	if method == http.MethodGet {
		v, _ := EncodeToStringWith(data, delimiter, escapee, keepZeros)
		regex := regexp.MustCompile(`\.\d+`)
		s := regex.ReplaceAllString(v, "")
		u.RawQuery = s
	}
	if method == http.MethodPost {
		valueReader = strings.NewReader(data.Encode())
	}
	req, err := http.NewRequest(method, u.String(), valueReader)
	if err != nil {
		return nil, err
	}
	req.SetBasicAuth(c.basicAuth())
	userAgent := fmt.Sprint("twilio-go/", config.LibraryVersion, " (", goVersion, ")")
	req.Header.Add("User-Agent", userAgent)
	if method == http.MethodPost {
		req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	}
	for k, v := range headers {
		req.Header.Add(k, fmt.Sprint(v))
	}
	return c.doWithErr(req)
}
func ( c * Client ) SendRequest ( method string , rawURL string , data url . Values , headers map [ string ] interface { } ) ( * http . Response , error ) { u , err := url . Parse ( rawURL ) if err != nil { return nil , err } valueReader := & strings . Reader { } goVersion := runtime . Version ( ) if method == http . MethodGet { v , _ := EncodeToStringWith ( data , delimiter , escapee , keepZeros ) regex := regexp . MustCompile ( `\.\d+` ) s := regex . ReplaceAllString ( v , " " ) u . RawQuery = s } if method == http . MethodPost { valueReader = strings . NewReader ( data . Encode ( ) ) } req , err := http . NewRequest ( method , u . String ( ) , valueReader ) if err != nil { return nil , err } req . SetBasicAuth ( c . basicAuth ( ) ) userAgent := fmt . Sprint ( " " , config . LibraryVersion , " " , goVersion , " " ) req . Header . Add ( " " , userAgent ) if method == http . MethodPost { req . Header . Add ( " " , " " ) } for k , v := range headers { req . Header . Add ( k , fmt . Sprint ( v ) ) } return c . doWithErr ( req ) }
SendRequest verifies, constructs, and authorizes an HTTP request.
SendRequest verifies constructs and authorizes an HTTP request .
// E.g. "User-Agent": "twilio-go/1.0.0 (go1.16)"