网页 综合 更新时间 2026-11-14 05:16:21

http package - net/http - Go Packages

自动蜘蛛 go.dev 正文约 3234 字
Common problems companies solve with Go
Stories about how and why companies use Go
How Go can help keep you secure by default
Tips for writing clear, performant, and idiomatic Go code
A complete introduction to building software with Go
Reference documentation for Go's standard library
Learn what's new in each Go release
Reference documentation for the pkg.go.dev API
Videos from prior events
Meet other local Go developers
Learn and network with Go developers from around the world
The Go project's official blog.
Get help and stay informed from Go
This package is not in the latest version of its module.
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Modules with tagged versions give importers more predictable builds.
When a project reaches major version v1 it is considered stable.
Package http provides HTTP client and server implementations.
Get, Head, Post, and PostForm make HTTP (or HTTPS) requests:
The caller must close the response body when finished with it:
For control over HTTP client headers, redirect policy, and other settings, create a Client:
For control over proxies, TLS configuration, keep-alives, compression, and other settings, create a Transport:
Clients and Transports are safe for concurrent use by multiple goroutines and for efficiency should only be created once and re-used.
ListenAndServe starts an HTTP server with a given address and handler. The handler is usually nil, which means to use DefaultServeMux. Handle and HandleFunc add handlers to DefaultServeMux:
More control over the server's behavior is available by creating a custom Server:
The http package has transparent support for the HTTP/2 protocol.
Server and DefaultTransport automatically enable HTTP/2 support when using HTTPS. Transport does not enable HTTP/2 by default.
To enable or disable support for HTTP/1, HTTP/2, and/or unencrypted HTTP/2, see the Server.Protocols and Transport.Protocols configuration fields.
To configure advanced HTTP/2 features, see the Server.HTTP2 and Transport.HTTP2 configuration fields.
Alternatively, the following GODEBUG settings are currently supported:
The "omithttp2" build tag may be used to disable the HTTP/2 implementation contained in the http package.
Common HTTP methods.
Unless otherwise noted, these are defined in RFC 7231 section 4.3.
HTTP status codes as registered with IANA. See: https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
DefaultMaxHeaderBytes is the maximum permitted size of the headers in an HTTP request. This can be overridden by setting Server.MaxHeaderBytes.
DefaultMaxHeaderValueCount is the maximum permitted number of header values in an HTTP request. This can be overridden by setting Server.MaxHeaderValueCount.
DefaultMaxIdleConnsPerHost is the default value of Transport's MaxIdleConnsPerHost.
TimeFormat is the time format to use when generating times in HTTP headers. It is like time.RFC1123 but hard-codes GMT as the time zone. The time being formatted must be in UTC for Format to generate the correct format.
For parsing this time format, see ParseTime.
访问原文 返回搜索 https://go.dev/pkg/net/http
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。