Skip to content
Advertisement

How to pass custom header to RESTful call?

There are some web service APIs that I need to connect to for my website. Most of the APIs involve something like this:

JavaScript

But one web service requires the API key to be set in a custom HTTP header. How do I make the request to this API url and pass the custom header at the same time?

Advertisement

Answer

You could use stream_context_create like this:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement