1 Star 0 Fork 0

lidedongsn/Go-test

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
http_download.go 712 Bytes
一键复制 编辑 原始数据 按行查看 历史
lidedongsn 提交于 2016-08-26 11:56 +08:00 . 第一次提交
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
resp, err := http.Get("http://mp.weixin.qq.com/s?__biz=MjM5OTAzMjc4MA==&mid=2650052511&idx=1&sn=0a955a324bcdee7a99820d76fe118d65&scene=4#wechat_redirect")
if err != nil {
//handleerror
fmt.Println(err)
log.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
fmt.Println(resp.StatusCode)
}
buf := make([]byte, 1024)
//createfile
f, err1 := os.OpenFile("baidu.html", os.O_RDWR|os.O_CREATE|os.O_APPEND, os.ModePerm)
if err1 != nil {
panic(err1)
return
}
defer f.Close()
for {
n, _ := resp.Body.Read(buf)
if 0 == n {
break
}
f.WriteString(string(buf[:n]))
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/lidecoolblue/Go-test.git
git@gitee.com:lidecoolblue/Go-test.git
lidecoolblue
Go-test
Go-test
master

搜索帮助