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:
12
geziyor.go
12
geziyor.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user