Skip to content
Advertisement

How to set proxy header in HttpURLConnection

I am trying to build an HTTP request to be sent via a proxy that accepts a proxy header. I am trying to find a way to set that, but couldn’t see it.

Below is the curl command which I need to convert to the Java code.

curl -i -u user:pwd -k GET –http1.1 –proxy-insecure https://localhost:8443 –proxy-header “X-Connect-Client-Id: abcde” https://target_host/api

This is what I was trying to do. `

JavaScript

Advertisement

Answer

You add headers in by calling setRequestProperty method:

JavaScript
Advertisement