5
Tôi đang gửi yêu cầu đến máy chủ nhưng nó đang trả về một trang web. Có cách nào để lấy url của trang web thay thế không?cách nhận url chuyển hướng thay vì nội dung trang trong golang?
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
req, err := http.NewRequest("GET", "https://www.google.com", nil)
if err != nil {
panic(err)
}
client := new(http.Client)
response, err := client.Do(req)
if err != nil {
panic(err)
}
fmt.Println(ioutil.ReadAll(response.Body))
}
các bản sao có thể có: http://stackoverflow.com/questions/24518945/ http://stackoverflow.com/questions/29865691/, http://stackoverflow.com/questions/27814942/ – JimB