rpreddy
(Pavan R)
1
Hello I am trying to send json payload to server using http.NewRequest. However getting error “http: ContentLength=222 with Body length 0” .
input,_ := json.Marshal(msgin)
req,_ := http.NewRequest(“POST”,url, bytes.NewBuffer(input))
req.Header.Set(“Content-Type”,“application/json”)
client := http.Client{Transport: defaultTransport}
resp, err := client.Do(req)
defer resp.Body.Close()
Don’t ignore the errors from json.Marshal and http.NewRequest maybe they are useful
rpreddy
(Pavan R)
3
Hello thanks for response
I have added err but couldn’t find issue in request, seems this is an issue with paylaod .
Again I have tried same payload using postman and it is working fine.m
rpreddy
(Pavan R)
4
I have Identified the issue with Header , It is posting properly after adding below header
req.Header.Add(“Accept”,"/").
1 Like
system
(system)
Closed
5
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.