我正在尝试将Authorization标头设置为我的http请求,但是当我在提交请求之前转储标头时,我会看到授权标头!
这是设置代码:
public void addRequestHeaders(HttpURLConnection a_urlConnection, UserData a_userData) {
a_urlConnection.setRequestProperty("Content-Type", "application/json");
a_urlConnection.setRequestProperty("X-Client-Information", "zzzzzzzzzzz");
String sAuthorization = createAuthorizationCode(a_userData);
String sAuthorizationEncoded = "Basic " + EncriptionManager.getInstance().Base64Encript(sAuthorization);
a_urlConnection.setRequestProperty("Authorization", sAuthorizationEncoded);
Dumpers.dumpRequest(a_urlConnection, m_sRequestBody);
}
转储代码是:
public static void dumpRequest(HttpURLConnection a_httpConnection, String a_sRequestBody) {
System.out.println("HttpPostRequest : sendHttpRequest: URL = " + a_httpConnection.getURL().toExternalForm());
System.out.println("HttpPostRequest : sendHttpRequest: Request Body = " + a_sRequestBody);
for (String header : a_httpConnection.getRequestProperties().keySet()) {
if (header != null) {
for (String value : a_httpConnection.getRequestProperties().get(header)) {
System.out.println(header + ":" + value);
}
}
}
}
输出结果为:
HttpPostRequest : sendHttpRequest: URL = https://ahemli- nexus.connectrnd.com/Att.Auth.Api/v1/authentication
HttpPostRequest : sendHttpRequest: Request Body =
X-Client-Information:zzzzzzzzzzz
Content-Type:application/json
你能告诉我吗?谢谢!