You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
756 B
Go

2 months ago
package httprequest
import (
"crypto/tls"
"fmt"
"net/http"
"strings"
)
func HttpRequest(url, method, requestBody string) (*http.Response, error) {
// TLS 설정
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // 인증서 검증 비활성화
}
client := &http.Client{Transport: tr}
// client := &http.Client{}
payload := strings.NewReader(requestBody)
req, _ := http.NewRequest(method, url, payload)
req.Header.Set("Content-Type", "application/json")
// 요청
res, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("요청 오류: %w", err)
}
if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("error: received non-200 response status: %s", res.Status)
}
return res, nil
}