简体   繁体   中英

Need to Set Default headers for all http requests

My app uses a 3rd party client to connect to a server. It offers an api for entering a user/pass. Unfortunately, the server we need to connect to also requires additional fields in the headers.

This client api hides its underlying HttpsURLConnection instance, so we can't set any headers.

HttpsURLConnection.setDefaultRequestProperty() would have solved my issue, but it is now deprecated.

Is there an alternative method to set headers on a global level?

This client api hides its underlying HttpsURLConnection instance, so we can't set any headers.

If the library is open source, modify it to add your headers.

If the library is not open source, you do not really know whether they are using HttpsUrlConnection or something else (eg, HttpClient).

Is there an alternative method to set headers on a global level?

Not in a way that somehow works across all possible HTTP client APIs, including hand-rolling an HTTP client using raw sockets.

You are also welcome to create your own Lightstream client ("The network protocol used by Lightstreamer is fully documented, so that you can directly develop your own client applications based on any other language and platform").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM