android - Add custom headers in volley request -


i have volley request code

requestqueue queue = volley.newrequestqueue(this); string url =<my url>;  // request string response provided url. stringrequest stringrequest = new stringrequest(request.method.get, url,             new response.listener<string>() {     @override     public void onresponse(string response) {         // display first 500 characters of response string.         mtextview.settext("response is: "+ response.substring(0,500));     } }, new response.errorlistener() {     @override     public void onerrorresponse(volleyerror error) {         mtextview.settext("that didn't work!");     } }); // add request requestqueue. queue.add(stringrequest); 

how set header called authorization in this??

you can write class extends request.(override getheaders() , on) like

public abstract class absrequest<t> extends request<t>{      public absrequest(int method, string url, response.errorlistener listener) {         this(method, url, null, listener);     }      public absrequest(int method, string url, map<string, string> params, response.errorlistener listener) {         this(method, url, params, null, listener);     }      public absrequest(int method, string url, map<string, string> params, map<string, string> head, response.errorlistener listener) {         this(method, url, params, head, null, listener);     }      public absrequest(int method, string url, map<string, string> params, map<string, string> head, string bodycontenttype, response.errorlistener listener) {         this(method, url, params, null, head, bodycontenttype, listener);     }      public absrequest(int method, string url, string body, map<string, string> head, string bodycontenttype, response.errorlistener listener) {         this(method, url, null, body, head, bodycontenttype, listener);     }      private absrequest(int method, string url, map<string, string> params, string body, map<string, string> head, string bodycontenttype,  response.errorlistener listener) {         super(method, url, listener);     } } 

for more information can see https://github.com/caij/codehub/blob/master/lib/src/main/java/com/caij/lib/volley/request/absrequest.java how use can see https://github.com/caij/codehub/tree/master/app/src/main/java/com/caij/codehub/presenter/imp


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -