interceptor - Retrofit 2.0 headers authentication -


private void setuprestclient() { okhttpclient client = new okhttpclient(); client.interceptors().add(new interceptor() { @override public response intercept(chain chain) throws ioexception { request original = chain.request(); request request = original.newbuilder() .header("accept", "application/pyur.v1") .header("authorization", new sharedpreferencesutil(getbasecontext()).gettoken()) .header("content-type", "application/json") .method(original.method(),original.body()) .build(); return chain.proceed(request); } }); restclient.getinstance().configurerestadapter(this, getresources().getstring(r.string.base_url),client); }

'public void configurerestadapter(final context context, string baseurl, okhttpclient client) {     gson gson = new gsonbuilder()             .setfieldnamingpolicy(fieldnamingpolicy.lower_case_with_underscores)             .setdateformat("yyyy-mm-dd't'hh:mm:ss.sss'z'")             .excludefieldswithmodifiers(modifier.final, modifier.transient, modifier.static)             .create();     retrofit retrofit = new retrofit.builder()             .baseurl(baseurl)             .addconverterfactory(gsonconverterfactory.create(gson))             .client(client)             .build();     service = retrofit.create(networkserviceinterface.class); }' 

this gives me failure return in retrofit 2.0, had without "authorization" header , giving me unauthorized, understandable. i'm authorizing auth token , fails. new retrofit 2.0, --

you can pass authorization header as:

@get("/v1/orderreport.json") call<pojo_class> getexamplemethod(@header("authorization") string token, @query("id") string id); 

and call as:

getexamplemethod("basic " + token, id); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -