1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-13 01:02:27 +08:00

添加GetPhoneNumberContext方法 (#587)

This commit is contained in:
stepbystep2
2022-07-28 00:08:08 +08:00
committed by GitHub
parent cc9be30ed1
commit 108a65ecf3
2 changed files with 27 additions and 7 deletions

View File

@@ -43,16 +43,21 @@ func HTTPGetContext(ctx context.Context, uri string) ([]byte, error) {
// HTTPPost post 请求
func HTTPPost(uri string, data string) ([]byte, error) {
return HTTPPostContext(context.Background(), uri, data)
return HTTPPostContext(context.Background(), uri, []byte(data), nil)
}
// HTTPPostContext post 请求
func HTTPPostContext(ctx context.Context, uri string, data string) ([]byte, error) {
body := bytes.NewBuffer([]byte(data))
func HTTPPostContext(ctx context.Context, uri string, data []byte, header map[string]string) ([]byte, error) {
body := bytes.NewBuffer(data)
request, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, body)
if err != nil {
return nil, err
}
for key, value := range header {
request.Header.Set(key, value)
}
response, err := http.DefaultClient.Do(request)
if err != nil {
return nil, err