1
我正在使用适用于Android的Spring的AndroidAnnotations。由于某些原因,API在每个请求中都需要特定的QueryString参数。所以我想通过拦截器添加它。适用于Android的Spring:为每个请求添加get参数
public class TestInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {
// how to safely add a constant querystring parameter to httpRequest here?
// e.g. http://myapi/test -> http://myapi/test?key=12345
// e.g. http://myapi/test?name=myname -> http://myapi/test?name=myname&key=12345
return clientHttpRequestExecution.execute(httpRequest, bytes);
}}
把实际问题的代码注释使用此请求工厂不是个好主意...... – m0skit0
你可以看到我是如何做到了这里的https:/ /Hithub.com/yDelouis/selfoss-android/blob/master/app/src/main/java/fr/ydelouis/selfoss/rest/SelfossApiInterceptor.java,在ApiHttpRequest子类中。我创建了另一个HttpRequest,它覆盖getURI()以返回修改后的URI。 – yDelouis
@ m0skit0事实上,问题在代码块之上。但是我认为在我想实现的目标上澄清我想实现的目标是个好主意。而且,我会更乐于提供更有帮助的评论,而不仅仅是抱怨我的问题的风格。 –