php - http.newRequest not sending post data -
i have following code send post data server, server not detecting post data on request. client code:
cookiejar, _ := cookiejar.new(nil) client := &http.client{ jar: cookiejar, } posturl := os.args[1] username := os.args[2] password := os.args[3] data := url.values{} data.set("username", username) data.add("password", password) data.add("remember", "false") r, _ := http.newrequest("post", posturl, bytes.newbufferstring(data.encode())) resp, _ := client.do(r) defer resp.body.close() body, err := ioutil.readall(resp.body) fmt.printf("%s\n", string(body))
server code:
if(isset($_post['username'], $_post['password'], $_post['remember'])){ echo $username = md5(($_post['username'])); echo $password_original = $_post['password']; echo $password = md5(($_post['password'])); echo $remember = $_post['remember']; }
you're posting data form in request body without content type. either need put values in request query:
r.url.rawquery = data.encode()
or change content-type "application/x-www-form-urlencoded":
r.header.add("content-type", "application/x-www-form-urlencoded")
Comments
Post a Comment