I have client code which is basically trying to upload a tar.gz file to the server using a HTTP PUT METHOD. However the server seems to not like it and always seems to send me a 500 ERROR Response. Following is the code. I am not sure what is going wrong.
func upLoadFileToServer (uploadFileName string) {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
ExpectContinueTimeout : 30 * time.Second,
}
client := &http.Client{ Transport:tr,
Timeout: 20 * time.Second}
timeCurrent = time.Now()
fileContents, err := ioutil.ReadFile(uploadFileName)
if err != nil {
log.Println("Failed to Read the File", uploadFileName, err)
}
PutReq, _ := http.NewRequest("PUT", "https://www.example.com/upload", strings.NewReader(string(fileContents)))
PutReq.Header.Set("Content-Type", "application/zip")
PutReq.ContentLength = int64(len(string(fileContents)))
PutReq.Header.Set("Expect", "100-continue")
PutReq.Header.Set("Accept", "*/*")
PutReq.Header.Set("Date", timeCurrent.Format(time.RFC1123))
PutResp, err := client.Do(inventoryPutReq)
}
Sometimes I notice Connection RESET by PEER error. But most of the times it is 500. I try the exact same request using POSTMAN and it seems to work fine.