"Go http.Get()"의 두 판 사이의 차이

(새 문서: ==개요== ;Go http.Get() <syntaxhighlight lang='go' run> package main import "fmt" import "net/http" import "io/ioutil" func main() { resp, _ := http.Get("https://raw.githubuser...)
 
 
(사용자 2명의 중간 판 15개는 보이지 않습니다)
4번째 줄: 4번째 줄:
<syntaxhighlight lang='go' run>
<syntaxhighlight lang='go' run>
package main
package main
import "fmt"
 
import "net/http"
import (
import "io/ioutil"
"fmt"
"io"
"net/http"
)
 
func main() {
func main() {
    resp, _ := http.Get("https://raw.githubusercontent.com/jmnote/test1/master/utf8test.txt")
resp, err := http.Get("https://jsonplaceholder.typicode.com/todos/1")
    body, _ := ioutil.ReadAll(resp.Body)
if err != nil {
    resp.Body.Close()
panic(err)
    fmt.Print("%s", string(body))
}
defer resp.Body.Close()
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(bodyBytes))
}
}
</syntaxhighlight>
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[같이보기]]
* [[Go 패키지 http]]
* [[Go NopCloser]]


==참고==
==참고==
* https://golang.org/pkg/net/http/
* https://golang.org/pkg/net/http/


[[분류: Go]]
[[분류:Go http 패키지]]
[[분류:Import "fmt"]]
[[분류:Import "net/http"]]
[[분류:Import "io"]]

2024년 6월 26일 (수) 16:12 기준 최신판

1 개요[ | ]

Go http.Get()
package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	resp, err := http.Get("https://jsonplaceholder.typicode.com/todos/1")
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	bodyBytes, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(bodyBytes))
}

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}