1. Home
  2. Docs
  3. golang
  4. 内置库(包-package)
  5. net-http

net-http

Function

http.ListenAndServe

func ListenAndServeTLS(addr, certFile, keyFile string, handler Handler) error


ListenAndServe listens on the TCP network address addr and then calls Serve with handler to handle requests on incoming connections. Accepted connections are configured to enable TCP keep-alives.

The handler is typically nil, in which case the DefaultServeMux is used.

ListenAndServe always returns a non-nil error.

ListenAndServe在TCP网络地址addr上监听,然后用处理程序调用Serve来处理进入的连接的请求。接受的连接被配置为启用TCP keep-alives。

处理程序通常为零,在这种情况下,会使用DefaultServeMux。

ListenAndServe总是返回一个非零的错误。

http.get

Get issues a GET to the specified URL. If the response is one of the following redirect codes, Get follows the redirect after calling the Client\\’s CheckRedirect function:

Get向指定的URL发出一个GET。如果响应是以下重定向代码之一,Get在调用客户端的CheckRedirect函数后跟随重定向。

http.Head

func (c <em>Client) Head(url string) (resp </em>Response, err error)


Head issues a HEAD to the specified URL. If the response is one of the following redirect codes, Head follows the redirect after calling the Client\’s CheckRedirect function:

Head向指定的URL发出一个HEAD。如果响应是以下重定向代码之一,Head在调用客户端的CheckRedirect函数后跟随重定向。

Types

type ResponseWriter interface

type ResponseWriter interface {
    Header() Header
    Write([]byte) (int, error)
    WriteHeader(statusCode int)
}

func NewServeMux

func NewServeMux() *ServeMux


NewServeMux分配并返回一个新的ServeMux。

type HandlerFunc

type HandlerFunc func(ResponseWriter, *Request)


The HandlerFunc type is an adapter to allow the use of ordinary functions as HTTP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.

HandlerFunc类型是一个适配器,允许使用普通函数作为HTTP处理程序。如果f是一个具有适当签名的函数,HandlerFunc(f)就是一个调用f的处理程序。

Was this article helpful to you? Yes No

How can we help?