package main
import (
"fmt"
"io"
"net/http"
"os"
)
var (
url = "http://127.0.0.1:1789/src/qq.exe"
)
func main() {
res, err := http.Get(url)
if err != nil {
panic(err)
}
f, err := os.Create("qq.exe")
if err != nil {
panic(err)
}
io.Copy(f, res.Body)
}
package main
import (
"bufio"
"fmt"
"io"
"net/http"
"os"
"path"
)
func main() {
imgPath := `E:\workspace\`
imgUrl := "http://hbimg.b0.upaiyun.com/32f065b3afb3fb36b75a5cbc90051b1050e1e6b6e199-Ml6q9F_fw320"
fileName := path.Base(imgUrl)
res, err := http.Get(imgUrl)
if err != nil {
fmt.Println("A error occurred!")
return
}
defer res.Body.Close()
reader := bufio.NewReaderSize(res.Body, 32 * 1024)
file, err := os.Create(imgPath + fileName + ".jpg")
if err != nil {
panic(err)
}
writer := bufio.NewWriter(file)
written, _ := io.Copy(writer, reader)
fmt.Printf("Total length: %d", written)
}