// Download is real function to downlaod file
Download is real function to downlaod file
// Download is real function to downlaod file
func (info *FileInfo) Download(output, username, password string) error {
	log.Debug().Msgf("%v", info)
	outputFile := info.GetOutput(output)
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: true},
		ResponseHeaderTimeout: timeout,
	}
	if proxy != "" {
		proxyURL, err := url.Parse(proxy)
		if err != nil {
			return err
		}
		tr = &http.Transport{
			TLSClientConfig:       &tls.Config{InsecureSkipVerify: true},
			Proxy:                 http.ProxyURL(proxyURL),
			ResponseHeaderTimeout: timeout,
		}
	}
	form := url.Values{}
	form.Add("Range", fmt.Sprintf("bytes=0-"))
	form.Add("hasAnnotation", "false")
	form.Add("includeAnnotation", "true")
	form.Add("seriesUid", info.SeriesUID)
	form.Add("sopUids", "")
	if username != "" && password != "" {
		form.Add("userId", username)
		form.Add("password", password)
	}
	req, err := http.NewRequest("POST", baseURL, strings.NewReader(form.Encode()))
	if err != nil {
		return errors.Wrapf(err, "failed to download while POST")
	}
	req.Header.Add("password", "")
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1")
	req.Header.Add("Connection", "Keep-Alive")
	log.Info().Msgf("Download %s to %s", info.SeriesUID, outputFile)
	client := &http.Client{Transport: tr, Timeout: timeout}
	resp, err := client.Do(req)
	if err != nil {
		return err
	}
	return UnTar(outputFile, resp.Body)
}
func ( info * FileInfo ) Download ( output , username , password string ) error { log . Debug ( ) . Msgf ( " " , info ) outputFile := info . GetOutput ( output ) tr := & http . Transport { TLSClientConfig : & tls . Config { InsecureSkipVerify : true } , ResponseHeaderTimeout : timeout , } if proxy != " " { proxyURL , err := url . Parse ( proxy ) if err != nil { return err } tr = & http . Transport { TLSClientConfig : & tls . Config { InsecureSkipVerify : true } , Proxy : http . ProxyURL ( proxyURL ) , ResponseHeaderTimeout : timeout , } } form := url . Values { } form . Add ( " " , fmt . Sprintf ( " " ) ) form . Add ( " " , " " ) form . Add ( " " , " " ) form . Add ( " " , info . SeriesUID ) form . Add ( " " , " " ) if username != " " && password != " " { form . Add ( " " , username ) form . Add ( " " , password ) } req , err := http . NewRequest ( " " , baseURL , strings . NewReader ( form . Encode ( ) ) ) if err != nil { return errors . Wrapf ( err , " " ) } req . Header . Add ( " " , " " ) req . Header . Add ( " " , " " ) req . Header . Add ( " " , " " ) log . Info ( ) . Msgf ( " " , info . SeriesUID , outputFile ) client := & http . Client { Transport : tr , Timeout : timeout } resp , err := client . Do ( req ) if err != nil { return err } return UnTar ( outputFile , resp . Body ) }
Download is real function to downlaod file
Download is real function to downlaod file
// custom the request form // custom the request header