Skip to content

Instantly share code, notes, and snippets.

@random-robbie
Created Dec 11, 2018
Embed
What would you like to do?
func tgetfiles(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
fmt.Fprintf(w, "ParseForm() err: %v", err)
return
}
APIKEY := r.FormValue("APIKEY")
TASK := r.FormValue("TASK")
enableCors(&w)
genurl := "https://myapi/api/v2/"+APIKEY+"/task/"+TASK+"/files.xml"
req, err := http.NewRequest("GET", genurl, nil)
if err != nil {
fmt.Println(err)
}
req.Host = "myapi"
req.Header.Set("Cache-Control", "no-cache")
req.Header.Set("User-Agent", "API Bridge GoLang")
req.Header.Set("Accept", "*/*")
req.Header.Set("Connection", "close")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
w.Header().Set("Content-Type", "application/xml")
w.WriteHeader(resp.StatusCode)
responseData, err := ioutil.ReadAll(resp.Body)
responseString := string(responseData)
fmt.Fprint(w, responseString)
if err != nil {
fmt.Println(err)
}
fmt.Printf("API URL: "+genurl+"\n")
fmt.Printf("API Status Code Response: %d\n", resp.StatusCode)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment