I am trying to send multiple headers (accept and auth key) with my request using HttpURLConnection, but only the first gets sent.
URL url = new URL(fileOrUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
for (String h : getHeaders()) {
String[] keyval = h.split(":");
if (keyval.length != 2) {
throw new IllegalArgumentException();
}
System.out.println("Setting header " + keyval[0] + ": " + keyval[1]);
conn.addRequestProperty(keyval[0], keyval[1]);
}
System.out.println(conn.getRequestProperties());
return stream = conn.getInputStream();
This results in:
Setting header Accept: application/x-google-protobuf
Setting header Authorization: apikey
{Accept=[ application/x-google-protobuf]}
Why is there only one header being sent?