I have a client API where the client API has headers:
req.Header.Set("Authorization", tokenBarear)
req.Header.Add("Content-Type", "application/json")
for token bearer which is set for the time limit. However when I run and test in postman it returns an error; so what's wrong with my code?
When I print using the following code tokenBarear := ctx.Get("Authorization")
generate correct token however when i call in headers using this
req.Header.Set("Authorization", tokenBarear)
req.Header.Add("Content-Type", "application/json")
the result is an error
client := &http.Client{}
jsonData, err := json.Marshal(params)
if err != nil {
return nil, exception.JSONParseExceptionMessage
}
payload := strings.NewReader(string(jsonData))
req, err := http.NewRequest("POST", repository.Configuration.Get("FLOW_URL_STAGING")+"/v2/inquiry", payload)
if err != nil {
return nil, fmt.Errorf("url issue")
}
cashinResponse := &response.CashinResponse{}
tokenBarear := ctx.Get("Authorization")
// contentType := ctx.Get("Content-Type")
req.Header.Set("Authorization", tokenBarear)
req.Header.Add("Content-Type", "application/json")
fmt.Println("tokens", tokenBarear)
// fmt.Println("content -type", contentType)
res, err := client.Do(req)
if err != nil {
fmt.Println("error disini", err)
return nil, err
}
json.NewDecoder(res.Body).Decode(&cashinResponse)
defer res.Body.Close()
fmt.Println("==============")
fmt.Println("Repository weblinking :", cashinResponse)
fmt.Println("==============")
return cashinResponse, nil