http client
This commit is contained in:
parent
11c71d2916
commit
0cffcf4fe6
@ -66,7 +66,7 @@ Epoch
|
|||||||
Флаги командной строки (Command-Line Flags)
|
Флаги командной строки (Command-Line Flags)
|
||||||
Подкоманды командной строки (Command-Line Subcommands)
|
Подкоманды командной строки (Command-Line Subcommands)
|
||||||
Переменные среды (Environment Variables)
|
Переменные среды (Environment Variables)
|
||||||
HTTP Clients
|
HTTP клиенты (HTTP Clients)
|
||||||
HTTP Servers
|
HTTP Servers
|
||||||
Spawning Processes
|
Spawning Processes
|
||||||
Exec'ing Processes
|
Exec'ing Processes
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// The Go standard library comes with excellent support
|
// Стандартная библиотека Go поставляется с отличной
|
||||||
// for HTTP clients and servers in the `net/http`
|
// поддержкой клиентов и серверов HTTP в пакете `net/http`.
|
||||||
// package. In this example we'll use it to issue simple
|
// В этом примере мы будем использовать его для
|
||||||
// HTTP requests.
|
// простых HTTP-запросов.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -12,21 +12,20 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Issue an HTTP GET request to a server. `http.Get` is a
|
// Отправьте HTTP-запрос GET на сервер. `http.Get` - это
|
||||||
// convenient shortcut around creating an `http.Client`
|
// удобный способ создания объекта `http.Client` и вызова
|
||||||
// object and calling its `Get` method; it uses the
|
// его метода `Get`; он использует объект `http.DefaultClient`,
|
||||||
// `http.DefaultClient` object which has useful default
|
// который имеет полезные настройки по умолчанию.
|
||||||
// settings.
|
|
||||||
resp, err := http.Get("http://gobyexample.com")
|
resp, err := http.Get("http://gobyexample.com")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
// Print the HTTP response status.
|
// Выведем статус http-ответа.
|
||||||
fmt.Println("Response status:", resp.Status)
|
fmt.Println("Response status:", resp.Status)
|
||||||
|
|
||||||
// Print the first 5 lines of the response body.
|
// Выведем первые 5 строк тела ответа.
|
||||||
scanner := bufio.NewScanner(resp.Body)
|
scanner := bufio.NewScanner(resp.Body)
|
||||||
for i := 0; scanner.Scan() && i < 5; i++ {
|
for i := 0; scanner.Scan() && i < 5; i++ {
|
||||||
fmt.Println(scanner.Text())
|
fmt.Println(scanner.Text())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user