This is a creation in Article, where the information may have evolved or changed.
The client Quick-cocos program is as follows:
Local info={hero={
Heroname= "Zhanshen", herolevel=1,herohp=200
},
[1]={
Name= "Fengbao", level=2,att=100
}
}
function Onrequestfinished (event)
Local OK = (Event.name = = "Completed")
Local request = Event.request
If not OK then
--Request failed with error code and error message displayed
Print (Request:geterrorcode (), Request:geterrormessage ())
Return
End
Local code = Request:getresponsestatuscode ()
If code ~=
--end of request, but no 200 response code returned
Print (code)
Return
End
--The request succeeds, showing the content returned by the server
Local response = Request:getresponsestring ()
Print (response)
End
--Create a request and send the data to the server by POST
Local URL = "Http://192.168.1.101:8080/test"
Local request = Network.createhttprequest (onrequestfinished, URL, "POST")
For key, value in pairs (info) does
For key,value in pairs (value) does
Print (Key,value)
Request:addpostvalue (key, value)
End
End
--Start the request. The callback () function is called when the request is complete
Request:start ()
Service-Side Golang program:
Package Main
Import (
"Encoding/json"
"FMT"
"Io/ioutil"
"Net/http"
"Strings"
)
Type person struct {
NAME string
Age int
}
Func Main () {
http. Handlefunc ("/test", hand)
ERR: = http. Listenandserve ("192.168.1.101:8080", nil)
If err! = Nil {
Fmt. Println ("Err")
}
}
Func Hand (w http. Responsewriter, R *http. Request) {
Fmt. Println ("OK")
W.write ([]byte ("Connect OK"))
R.parseform ()//parse parameter, default is not resolved
Fmt. PRINTLN (R.form)//These are server-side printing information
Fmt. PRINTLN ("Path", R.url. Path)
Fmt. PRINTLN ("scheme", R.url. Scheme)
Fmt. Println (r.form["Url_long"])
For k, V: = Range R.form {
Fmt. Println ("Key:", K)
Fmt. The type of Println ("Val:", v)//v is []string
}
}
Remember to replace the IP address with your own