Compare commits
No commits in common. "master" and "v1.2.6" have entirely different histories.
22
README.MD
22
README.MD
@ -1,11 +1,10 @@
|
||||
# simpleRequest
|
||||
_# simpleRequest
|
||||
## 1. 说明
|
||||
[simpleRequest](www.github.com/dorlolo/simpleRequest) 是一款面向对象的http请求库,它在Go原生的http库为基础做了一定的封装,使开发更加便捷。
|
||||
|
||||
> [simpleRequest](www.github.com/dorlolo/simpleRequest) 具备以下特点:
|
||||
- 没有在代码层面遵循restful规范,适合对接不符合规范的接口;
|
||||
- 轻量级、不需要繁琐的配置;
|
||||
- 易于理解和使用,减少了资料查询的时间。
|
||||
[simpleRequest](www.github.com/dorlolo/simpleRequest) 是一款面向对象开发的http请求库。他是基于Go原生http库。开发这个模块的主要目的是为了更快的对接第三方api接口。
|
||||
它具备以下特点:
|
||||
- 极简化的代码,大大提高了代码编写速度。
|
||||
- 更易于理解和使用,减少了资料查询的时间。
|
||||
- 更适合对接一些不遵循restful规范的接口。
|
||||
|
||||
这是它的一个示例:
|
||||
```go
|
||||
@ -62,13 +61,12 @@ r.Headers().Set("token", "d+jfdji*D%1=").Set("Content-Type", "application/json")
|
||||
```
|
||||
|
||||
#### 2.4.4 添加多值
|
||||
|
||||
对单个key添加多只不要使用`.set`,因为原先的值会被覆盖
|
||||
```go
|
||||
// 对相同key的值进行覆盖,请使用Set方法
|
||||
r.Headers().Set("Accept", "text/html")
|
||||
// 对相同key的值进行追加,请使用Add方法
|
||||
r.Headers().Add("Accept","application/xhtml+xml")
|
||||
r.Headers().Add("Accept","application/xml;q=0.8")
|
||||
r.Headers().Add("Accept","image/webp")
|
||||
r.Headers().Add("Accept","*/*;q=0.8")
|
||||
```
|
||||
|
||||
@ -243,7 +241,7 @@ func FileForwardUseBytesBody(c *gin.Context){
|
||||
writer = multipart.NewWriter(body)
|
||||
)
|
||||
// add file object
|
||||
filePart, _ := writer.CreateFormFile("file", file.Filename)
|
||||
filePart, _ := i.writer.CreateFormFile("file", file.Filename)
|
||||
src, err := file.Open()
|
||||
if err != nil {
|
||||
fmt.Println( err.Error())
|
||||
@ -327,4 +325,4 @@ responseContext:=r.Response
|
||||
```
|
||||
|
||||
## 3. 使用示例
|
||||
[simpleRequest_test.go](excample/simpleRequest_test.go)
|
||||
[simpleRequest_test.go](excample/simpleRequest_test.go)_
|
@ -54,7 +54,7 @@ type SimpleRequest struct {
|
||||
BodyEntries map[string]any // 输入的body中的内容
|
||||
bodyEntryParsers map[string]IBodyEntryParser // 用于将BodyEntries中的内容解析后传入request body中
|
||||
disableDefaultContentType bool // 禁用默认的ContentType
|
||||
disableCopyRequestBody bool // 禁用复制请求体,在进行http请求后SimpleRequest.Request.Body中内容会无法读取,但是会提高性能
|
||||
disableCopyRequestBody bool // 禁用默认的ContentType,在进行http请求后SimpleRequest.Request.Body中内容会无法读取
|
||||
|
||||
timeout time.Duration
|
||||
|
||||
@ -173,15 +173,12 @@ func (s *SimpleRequest) GET(urls string) (body []byte, err error) {
|
||||
|
||||
// 通用的请求方法
|
||||
func (s *SimpleRequest) LaunchTo(urls, method string) (body []byte, err error) {
|
||||
var r *http.Request
|
||||
// body
|
||||
s.initBody()
|
||||
var copBody []byte
|
||||
if s.body != nil {
|
||||
copBody, err = io.ReadAll(s.body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var r *http.Request
|
||||
copBody, err := io.ReadAll(s.body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if !s.disableCopyRequestBody {
|
||||
// 使r.body在请求后仍旧可读,便于使用者对请求过程进行分析
|
||||
|
Loading…
Reference in New Issue
Block a user