Many examples showed adding header should:
Request request = new Request.Builder()
.url("https://api.github.com/repos/square/okhttp/issues")
.header("User-Agent", "OkHttp Headers.java")
.addHeader("Accept", "application/json; q=0.5")
.addHeader("Accept", "application/vnd.github.v3+json")
.build();
But I want to dynamically add headers as user's header requirements, how can I implement it?
Headers h = new Headers.Builder().build();
for (HttpHeader hh : ht.HttpRequestHeader) {
h.newBuilder().add(hh.Name, hh.Value);
} //<<---Nothing changed!!!!!
Headers.Builder builder = new Headers.Builder();
for (HttpHeader hh : ht.HttpRequestHeader) {
builder.add(hh.Name, hh.Value);
}
Headers h = builder.build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With