Documentation
¶
Index ¶
Constants ¶
const ( // Text 纯文本类型 Text = "text/plain" // JavaScript JavaScript 脚本内容类型 JavaScript = "application/javascript" // Json JSON 数据类型 Json = "application/json" // Html HTML 文本类型 Html = "text/html" // Xml XML 数据类型 Xml = "application/xml" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Body ¶
type Body interface {
// GetData 返回当前请求体的原始数据内容(字符串形式)
// 通常用于调试或日志,不一定是最终发送的格式
GetData() string
// GetContentType 返回该请求体对应的 Content-Type 值
// 用于在 HTTP 请求头中设置正确的 MIME 类型
GetContentType() string
// Encode 将当前请求体编码为 io.Reader,供 HTTP 请求作为 body 使用
// 每个实现通常根据自身所需格式返回相应的 Reader
Encode() io.Reader
}
Body 定义了可作为 HTTP 请求体的统一接口 所有请求体类型(如 Raw、Url、Form 等)都应实现该接口 通过该接口,外部在构建请求时可以以统一方式获取内容、类型与最终编码形式
type Form ¶
type Form struct {
// contains filtered or unexported fields
}
Form 用于构建 multipart/form-data 类型的表单请求体 支持添加普通字段与文件字段,并最终编码为可用于 HTTP 请求的 io.Reader
func NewFormData ¶
func NewFormData() *Form
NewFormData 创建一个新的 Form 实例 返回的 Form 可用于设置字段、文件内容并生成 multipart/form-data 请求体
func (*Form) Encode ¶
Encode 关闭 multipart.Writer 并返回完整的 multipart/form-data 编码内容 返回的 io.Reader 可直接作为 HTTP 请求 body 注意:调用 Encode() 后将无法再次向 Form 中添加字段
func (*Form) GetContentType ¶
GetContentType 返回该表单对应的 Content-Type,包含 boundary
func (*Form) SetBoundary ¶
SetBoundary 手动设置 multipart/form-data 边界值 一般情况下不需要手动设置边界,除非对外兼容性有特殊要求
type Raw ¶
type Raw struct {
// contains filtered or unexported fields
}
Raw 用于构建原始字符串类型的请求体(raw body) 可用于发送 JSON、XML、纯文本或任意自定义格式的数据
func NewRawData ¶
func NewRawData() *Raw
NewRawData 创建一个空的 Raw 请求体对象 通过 SetData 设置内容和格式,最终 Encode 生成 io.Reader
func (*Raw) GetContentType ¶
GetContentType 返回当前 Raw 数据的 Content-Type 字段
type Url ¶
type Url struct {
// contains filtered or unexported fields
}
Url 用于构建 application/x-www-form-urlencoded 请求体 通过内部维护的 url.Values 实现键值对表单数据的编码
func NewUrlEncode ¶
func NewUrlEncode() *Url
NewUrlEncode 创建一个新的 Url 实例,用于构建 URL-encoded 表单数据 返回的 Url 可继续通过 SetData 添加字段,最终 Encode 为 io.Reader
func (*Url) GetContentType ¶
GetContentType 返回该类型的 Content-Type