Syntax for passing parameters in HTTP POST Request -


right have working poc api returns product based on product id. can test api using swagger. vb6 code follows:

public function webrequestpost(surl string) string     dim xmlhttp msxml2.xmlhttp      set xmlhttp = createobject("msxml2.serverxmlhttp")     xmlhttp.open "post", surl, false     xmlhttp.setrequestheader "content-type", "application/x-www-form-urlencoded"     xmlhttp.send "{""id"":2}"     webrequestpost = xmlhttp.responsetext      set xmlhttp = nothing  end function  private sub command2_click()     dim result string     dim url string     dim productid string      url = "http://localhost:1112/api/products"     result = webrequestpost(url)      msgbox result  end sub 

i have used similar code method , passing parameter through url success, can't seem post method working. have feeling lies in xmlhttp.send method.

it worked reformatting:

xmlhttp.setrequestheader "content-type", "application/x-www-form-urlencoded"

to

xmlhttp.setrequestheader "content-type", "application/json"

and passing payload in form of: xmlhttp.send 2

which made variable passed parameter in form of xmlhttp.send sid

ultimately ending with:

public function webrequestpost(surl string, sid integer) string     dim xmlhttp msxml2.xmlhttp      set xmlhttp = createobject("msxml2.serverxmlhttp")     xmlhttp.open "post", surl, false     xmlhttp.setrequestheader "content-type", "application/json"     xmlhttp.send sid     webrequestpost = xmlhttp.responsetext      set xmlhttp = nothing  end function  private sub command2_click()     dim result string     dim url string     dim productid string      url = "http://localhost:1112/api/products"     result = webrequestpost(url, 3)      msgbox result  end sub 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -