Feature: Implement Geziyor.Post which wraps the httpClient(POST)

1. Implement Geziyor.Post by the same style of Geziyor.Head
2. Add two examples in geziyor_test (TestPostJson, TestPostFormUrlEncoded)

issue #38
This commit is contained in:
walker088
2021-10-21 09:06:34 -03:00
parent 6415a775f4
commit b1e4683037
2 changed files with 65 additions and 3 deletions

View File

@@ -9,6 +9,8 @@ import (
"github.com/geziyor/geziyor/metrics"
"github.com/geziyor/geziyor/middleware"
"golang.org/x/time/rate"
"io"
"io/ioutil"
"net/http/cookiejar"
"os"
@@ -203,6 +205,16 @@ func (g *Geziyor) Head(url string, callback func(g *Geziyor, r *client.Response)
g.Do(req, callback)
}
// Post issues a POST to the specified URL
func (g *Geziyor) Post(url string, body io.Reader, callback func(g *Geziyor, r *client.Response)) {
req, err := client.NewRequest("POST", url, body)
if err != nil {
internal.Logger.Printf("Request creating error %v\n", err)
return
}
g.Do(req, callback)
}
// Do sends an HTTP request
func (g *Geziyor) Do(req *client.Request, callback func(g *Geziyor, r *client.Response)) {
if g.shutdown {