이 름 : 바다아이
|
조회수 : 10273
짧은 주소 : https://www.bada-ie.com/su/?21591832956
// Go contains rich function for grab web contents. _net/http_ is the major// library.// Ref: [golang.org](http://golang.org/pkg/net/http/#pkg-examples).package main
import (
"net/http""net/url"
)
import"io/ioutil"import"fmt"import"strings"// keep first n linesfunckeepLines(s string, n int)string {
result := strings.Join(strings.Split(s, "\n")[:n], "\n")
return strings.Replace(result, "\r", "", -1)
}
funcmain() {
// We can use GET form to get result.
resp, err := http.Get("http://g.cn/robots.txt")
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
fmt.Println("get:\n", keepLines(string(body), 3))
// We can use POST form to get result, too.
resp, err = http.PostForm("http://duckduckgo.com",
url.Values{"q": {"github"}})
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err = ioutil.ReadAll(resp.Body)
fmt.Println("post:\n", keepLines(string(body), 3))
}
출처 : https://dlintw.github.io/gobyexample/public/http-client.html
|
|
번 호
카테고리
제 목
이름
조회수
Copyright ⓒ 2001.12. bada-ie.com. All rights reserved.
이 사이트는 리눅스에서 firefox 기준으로 작성되었습니다. 기타 브라우저에서는 다르게 보일 수 있습니다.
[ Ubuntu + GoLang + PostgreSQL + Mariadb ]
서버위치 : 오라클 클라우드 춘천 실행시간 : 0.17796 초 to webmaster... gogo sea. gogo sea.