我需要在我的Android应用中发送自定义标头,我使用android studio http://docs.servicestack.net/java-add-servicestack-reference的
在net.servicestack.client.JsonServiceClient类中存在该字段 公共静态连接过滤器GlobalRequestFilter ,我可以将其用于发送自定义标头吗?谢谢
答案 0 :(得分:2)
是的,您可以在AndroidServiceClient
实例上设置HTTP标头:
AndroidServiceClient client = new AndroidServiceClient(baseUrl);
client.RequestFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
conn.setRequestProperty("X-header", "value");
}
};
Java 8:
client.GlobalRequestFilter = conn -> conn.setRequestProperty("X-header", "value");
或全局到所有服务客户端请求:
AndroidServiceClient.GlobalRequestFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
conn.setRequestProperty("X-header", "value");
}
};
Java 8:
AndroidServiceClient.GlobalRequestFilter = conn ->
conn.setRequestProperty("X-header", "value");