3. Setting the request type and parameters
Volley the default request type is get, which can be set in the constructor if a post is required. Setting parameters can be implemented by overriding the Getparams () method.
Private voidpostrequest () {jsonobjectrequest postobjectrequest=Newjsonobjectrequest (Method.post,"Http://192.168.199.18:8080/myhos/query", NULL, NewResponse.listener<jsonobject>() {@Override Public voidOnresponse (jsonobject response) {LOG.I ("Response:", response.tostring ()); } }, NewResponse.errorlistener () {@Override Public voidonerrorresponse (volleyerror error) {LOG.I ("Error:", Error.getmessage (), error); }}) {@OverrideprotectedMap<string, string> getparams ()throwsAuthfailureerror {Map<string, string> map =NewHashmap<string, string>(); Map.put ("QID", "446"); Map.put ("Count", "10"); Map.put ("Page", "1"); returnmap; } }; Mqueue.add (postobjectrequest); }
In the code above, another constructor for the volley request is used, the request is specified as post by Method.post, and three parameters are set by overriding the Getparams () method. The results of the operation are as follows:
Use of Android Volley framework (2)