mrk
(Mrk)
June 5, 2018, 7:43am
1
gid_token := r.Header.Get("Authorization")
request_url_gid := r.RequestURI
jmb_gid_url := gid_env_url + request_url_gid
body :=r.Body
fmt.Print("%T",body)
c_type :=r.Header.Get("Content-Type")
fmt.Println("c_type",c_type)
req, _ := http.NewRequest("POST", jmb_gid_url,body)
req.Header.Add("Authorization","xxxxxx")
req.Header.Add("Content-Type","application/json")
fmt.Println(req)
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
bodynew, _ := ioutil.ReadAll(resp.Body)
fmt.Fprintf(w, "%s", bodynew)
}
lutzhorn
(Lutz Horn)
June 5, 2018, 7:46am
2
Please edit your post and indent every line of code with four spaces. The </>
button will help you with that.
lutzhorn
(Lutz Horn)
June 5, 2018, 7:52am
4
No problem.
Regarding your question: You’ve just posted a snippet of code but you do not tell us what this code is supposed to do, if it is doing what you want it to do, or if there is any problem or error. What is your question?
mrk
(Mrk)
June 5, 2018, 7:54am
5
i want to send Json Body but that is not going as part of the request
acim
(Boban Acimovic)
June 6, 2018, 9:31am
6
// q is your struct
// url is your url.URL
body := &bytes.Buffer{}
if err := json.NewEncoder(body).Encode(&q); err != nil {
panic(err)
}
req, err := http.NewRequest(http.MethodPost, url.String(), body)
mrk
(Mrk)
June 6, 2018, 9:32am
7
thanks
My version : req, err := http.NewRequest(“POST”, url, strings.NewReader(r.Form.Encode()))
mrk
(Mrk)
June 6, 2018, 9:46am
8
hi i have 1 question . Even if the values r empty how can i send only the fields to the api
acim
(Boban Acimovic)
June 6, 2018, 9:54am
9
Use struct with json annotations.
system
(system)
Closed
September 4, 2018, 9:54am
10
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.