i converting application use volley framework.
i have working far can tell, when make webservice request using httpclient, wireshark showing parameters
deviceprint=android&mobilesaveuserid=false&__responsetype=xml&appversion=android-3.2&__responsetypeversion=1.0&userid=mbltest6&retrievepostedtransaction=falsehttp/1.1 200 ok
this works perfectly, when use volley, packet looks this.
deviceprint=android&mobilesaveuserid=false&__responsetype=xml&appversion=android-3.2&__responsetypeversion=1.0&userid=mbltest6&retrievepostedtransaction=false&http/1.1 200 ok
i moved them side side , noticed volley example (the bottom one) appending "&" causing webservice return "username not found" though in there.
any suggestions on how fix this? or why it's happening?
edit: upon further investigation base classes, when set parameters adds "&" end of string. normal behavior volley? whats causing request fail?
private byte[] encodeparameters(map<string, string> params, string paramsencoding) { stringbuilder encodedparams = new stringbuilder(); try { iterator uee = params.entryset().iterator(); while(uee.hasnext()) { java.util.map.entry entry = (java.util.map.entry)uee.next(); encodedparams.append(urlencoder.encode((string)entry.getkey(), paramsencoding)); encodedparams.append('='); encodedparams.append(urlencoder.encode((string)entry.getvalue(), paramsencoding)); encodedparams.append('&'); } return encodedparams.tostring().getbytes(paramsencoding); } catch (unsupportedencodingexception var6) { throw new runtimeexception("encoding not supported: " + paramsencoding, var6); } }
my code follows:
public abstract class webservicerequest extends stringrequest { private static final int socket_timeout = (1000 * 60); private static final string response_type_key = "__responsetype"; private static final string response_type_version_key = "__responsetypeversion"; private static final string app_version_key = "appversion"; private static final string retrieve_posted_key = "retrievepostedtransaction"; public boolean mretrievepostedtransactions; private map<string, string> mparameters; public webservicerequest(string url, response.listener<string> listener, response.errorlistener errorlistener) { super(method.post, url, listener, errorlistener); this.mparameters = new hashmap<>(); setretrypolicy(new defaultretrypolicy( socket_timeout, defaultretrypolicy.default_max_retries, defaultretrypolicy.default_backoff_mult )); } public abstract void setparams(map<string,string> params); @override protected map<string, string> getparams() throws authfailureerror { setcommonparameters(mparameters); setparams(mparameters); return mparameters; } private map<string, string> setcommonparameters (map<string,string> params) { params.put( app_version_key, "android-" + virtualwalletapplication.getinstance().appversion ); params.put( response_type_key, "xml" ); params.put( response_type_version_key, "1.0" ); params.put( retrieve_posted_key, boolean.valueof( mretrievepostedtransactions ).tostring() ); return params; }
}
here create request
webservicerequest request = new webservicerequest( stringutils.getfullserverurlforresource("/alservlet/validateuseridservlet"), onsuccesslistener, onfailurelistener) { @override public void setparams(map<string, string> params) { params.put("userid","mbltest6"); params.put("mobilesaveuserid","false"); params.put("deviceprint","android"); } }; networkvolley.getinstance().sendrequest(request);
turns out, needed capitalize parameter "userid" not "userid". keep close eye on parameters people!
Comments
Post a Comment