func httpGet(url string) (ret string){
resp, err := http.Get(url)
if err != nil {
// handle error
}
defer func() {
if(resp == nil){
return
}else if(resp.Body == nil){
return
}
resp.Body.Close()
}()
if(resp == nil || resp.Body == nil){
return ""
}
body, err := ioutil.ReadAll(resp.Body)
if(err != nil || body == nil ){
log.Println("httpGet error : ",err.Error()," body = ",body)
return ""
}
return string(body)
}
func httpPost(requestUrl string, paramMap map[string]string) (ret string) {
params := url.Values{}
for key, value := range paramMap {
params.Add(key, value)
}
resp, _ := http.PostForm(requestUrl,params);
defer func() {
if(resp == nil){
return
}else if(resp.Body == nil){
return
}
resp.Body.Close()
}()
if(resp == nil || resp.Body == nil){
return ""
}
body,err:= ioutil.ReadAll(resp.Body)
if(err != nil || body == nil){
log.Println("httpPost error : ",err.Error()," body = ",body)
return ""
}
return string(body)
}
网友评论