🚑 Fixed content-type of requests
This commit is contained in:
parent
62cec7b9b1
commit
706baf4a24
20
telegram.go
20
telegram.go
|
@ -14,18 +14,30 @@ const (
|
|||
)
|
||||
|
||||
func (bot *Bot) request(dst []byte, method string, args *http.Args) (*Response, error) {
|
||||
_, resp, err := http.Post(dst, fmt.Sprintf(APIEndpoint, bot.AccessToken, method), args)
|
||||
if err != nil {
|
||||
requestURI := fmt.Sprintf(APIEndpoint, bot.AccessToken, method)
|
||||
if &args != nil {
|
||||
requestURI += fmt.Sprint("?", args.String())
|
||||
}
|
||||
|
||||
var req http.Request
|
||||
var resp http.Response
|
||||
|
||||
req.Header.SetMethod("POST")
|
||||
req.Header.SetContentType("application/json")
|
||||
req.SetRequestURI(requestURI)
|
||||
req.SetBody(dst)
|
||||
|
||||
if err := http.Do(&req, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var data Response
|
||||
if err := json.Unmarshal(resp, &data); err != nil {
|
||||
if err := json.Unmarshal(resp.Body(), &data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !data.Ok {
|
||||
return &data, errors.New(data.Description)
|
||||
return nil, errors.New(data.Description)
|
||||
}
|
||||
|
||||
return &data, nil
|
||||
|
|
Loading…
Reference in New Issue