Regard, Can anyone convert me this working code to Colly. Thank you
package main
import (
"fmt"
"net/http"
"strings"
"io/ioutil"
)
func main() {
url := "http://1024game.org/api"
payload := strings.NewReader(`term=4404094910003`)
req, _ := http.NewRequest("POST", url, payload)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
You can try something like this:
package main
import (
"net/http"
"strings"
"github.com/gocolly/colly"
)
func main() {
c := colly.NewCollector()
c.Request("POST",
"http://1024game.org/api",
strings.NewReader(`term=4404094910003`),
nil,
http.Header{"Content-Type": []string{"application/x-www-form-urlencoded"}}
)
}
Can you please write how to read response?
Thank you
@mishop
c := colly.NewCollector()
// here
c.OnResponse(func(r *colly.Response) {
log.Println("resp", string(r.Body))
})
c.Request("POST",
"http://1024game.org/api",
strings.NewReader(`term=4404094910003`),
nil,
http.Header{"Content-Type": []string{"application/x-www-form-urlencoded"}}
)
Most helpful comment
Can you please write how to read response?
Thank you