Thanks for taking time to answer my question. I have put the actual data except the loginId header..
https://play.golang.org/p/KrnxWLVj8s2 But i still get the html content in golang but when i use python i get the invalid api credentials. Due to incorrect loginId header. import requests r = requests.get("https://www.dncscrub.com/app/main/rpc/scrub", params={'version': '5', "phoneList": "2123727200"}, headers={"loginId": "0610A62F"}) print r.text So, responses are totally different from two languages. Python looks correct. Ryan On Sun, 20 Sep 2020 at 11:10, burak serdar <bser...@computer.org> wrote: > On Sat, Sep 19, 2020 at 11:47 PM Tamás Gulácsi <tgulacs...@gmail.com> > wrote: > > > > I bet requests (and curl) encodes the params as multipart/form-data, NOT > query string. > > Do the same: https://play.golang.org/p/L4YryKNjju4 > > A GET request does not have a body. > > I suggest you print out the request struct completely before > submitting it, with the headers and URL and everything, and then maybe > you can pinpoint the problem. > > > > > remb...@gmail.com a következőt írta (2020. szeptember 19., szombat, > 20:44:54 UTC+2): > >> > >> I am trying to call a simple api by using golang. But, each time it > sends me html content of login page instead of actual data. But same get > request works from python and curl. > >> > >> package main > >> > >> import ( > >> "fmt" > >> "io/ioutil" > >> "net/http" > >> "os" > >> ) > >> > >> func main() { > >> > >> client := &http.Client{} > >> req, err := http.NewRequest("GET", "https://www.lrn.com", nil) > >> if err != nil { > >> os.Exit(1) > >> } > >> > >> q := req.URL.Query() > >> q.Add("phoneList", "XXXXXX") > >> q.Add("output", "json") > >> q.Add("version", "5") > >> //req.URL.RawQuery = q.Encode() > >> req.Header.Set("loginId", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") > >> > >> fmt.Println(req.URL.String()) > >> > >> resp, err := client.Do(req) > >> > >> if err != nil { > >> fmt.Println("Errored when sending request to the server") > >> return > >> } > >> > >> defer resp.Body.Close() > >> resp_body, _ := ioutil.ReadAll(resp.Body) > >> > >> fmt.Println(resp.Status) > >> fmt.Println(string(resp_body)) > >> } > >> Above script gives me html content of login page. But if i use python, > it works just fine. > >> > >> import requests > >> > >> r=requests.get("https://www.lrn.com", params = {'version':'5', > "phoneList":"XXXXXX", "output":"json"}, > headers={"loginId":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX "}) > >> > >> print r.text > >> > >> Could someone please explain me what might be wrong in my golang script. > >> > >> Ryan. > > > > -- > > You received this message because you are subscribed to the Google > Groups "golang-nuts" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to golang-nuts+unsubscr...@googlegroups.com. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/95c62bc9-7772-4309-907d-09590dae9a25n%40googlegroups.com > . > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/CAMV2RqrvsdZvTfBax1Z2Ke0YL%3DzVtp20WBUMfnyB%2BLNwOVQLiw%40mail.gmail.com > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAJ_X8k6SGu0NbpSGH1xwaVwDBivgUsZAqu2goSY%3Du-7t8mhByQ%40mail.gmail.com.