记录一段j简单的demo供有需要的人直接使用
package main
import (
"fmt"
"io"
"net/http"
)
func Do(method string, url string, payload io.Reader) (*http.Response, error) {
req, err := http.NewRequest(method, url, payload)
if err != nil {
return nil, err
}
// Set the auth for the request.
req.SetBasicAuth("admin", "Admin@123")
return http.DefaultClient.Do(req)
}
func main() {
json := `{"type": "s3", "settings": {"bucket": "testningxia", "region": "cn-northwest-1", "role_arn": "arn:aws-cn:iam::092513309139:instance-profile/TheSnapshotRole"}}`
payload := strings.NewReader(json)
req,_ := Do("GET","https://es.amazonaws.com.cn",payload)
body,_:=io.ReadAll(req.Body)
fmt.Println(string(body))
}