
我想用自定义标头发出POST请求.我无法使用AA Rest API – https://github.com/excilys/androidannotations/wiki/Rest%20API找到有关如何执行此 *** 作的信息.
我应该使用ClIEnthttpRequestInterceptor,它用于经过身份验证的请求吗?
https://github.com/excilys/androidannotations/wiki/Authenticated-Rest-Client
谢谢你的帮助!
解决方法:
目前有一个未解决的问题:https://github.com/excilys/androidannotations/issues/323
目前,唯一的方法是使用自定义ClIEnthttpRequestInterceptor.这是一个小例子:
@EBeanpublic class CustomheaderInterceptor implements ClIEnthttpRequestInterceptor { @OverrIDe public ClIEnthttpResponse intercept(httpRequest request, byte[] data, ClIEnthttpRequestExecution execution) throws IOException { request.getheaders().add("myheader", "value"); return execution.execute(request, data); }}然后,您需要将它链接到restTemplate,如下所示:
@EBeanpublic class MyService { @RestService RestClIEnt restClIEnt; @Bean MobileParametersInterceptor mobileParametersInterceptor; @AfterInject public voID init() { List<ClIEnthttpRequestInterceptor> interceptors = new ArrayList<ClIEnthttpRequestInterceptor>(); interceptors.add(mobileParametersInterceptor); restClIEnt.getRestTemplate().setInterceptors(interceptors); }} 总结 以上是内存溢出为你收集整理的android – Rest API – 如何添加自定义标头?全部内容,希望文章能够帮你解决android – Rest API – 如何添加自定义标头?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)