Программисты JAVA общаются здесь
-
Anonymous
Почему при печати свойств запроса HttpURLConnection одного из них нет?
Сообщение
Anonymous »
Добрый день.
Я использую приведенный выше код Java для подключения к внешнему серверу.
Это код:
Код: Выделить всё
URL url = new URL("api-url");
HttpURLConnection hpcon = (HttpURLConnection)url.openConnection();
byte[] authBytes = grantprovider.getBytes(StandardCharsets.UTF_8);
String grant_encoded = Base64.getEncoder().encodeToString(authBytes);
hpcon.setRequestProperty("Authorization", "Basic " + grant_encoded);
hpcon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
hpcon.setRequestMethod("POST");
hpcon.setDoInput(true);
hpcon.setDoOutput(true);
hpcon.setUseCaches(false);
Map map = hpcon.getRequestProperties();
for (Map.Entry entry : map.entrySet())
{
System.out.println("Key : " + entry.getKey() + " ,Value : " + entry.getValue());
}
Map hdrs = hpcon.getHeaderFields();
Set hdrKeys = hdrs.keySet();
for (String k : hdrKeys) {
System.out.println("Property Key: " + k + " - Property Value: " + hdrs.get(k));
}
for (Map.Entry entries : hpcon.getRequestProperties().entrySet()) {
String values = "";
for (String value : entries.getValue()) {
values += value + ",";
}
System.out.println("Request - " + entries.getKey() + " - " + values );
}
String postData = "grant_type=client_credentials";
try(OutputStream os = hpcon.getOutputStream()) {
byte[] input = postData.getBytes("utf-8");
os.write(input, 0, input.length);
}
hpcon.connect();
Почему, когда я печатаю свойства запроса одним из указанных выше способов, свойство «Авторизация» не появляется?
С уважением.
Стефано Эррани
Подробнее здесь:
https://stackoverflow.com/questions/786 ... ot-present
1719309009
Anonymous
Добрый день.
Я использую приведенный выше код Java для подключения к внешнему серверу.
Это код:
[code]URL url = new URL("api-url");
HttpURLConnection hpcon = (HttpURLConnection)url.openConnection();
byte[] authBytes = grantprovider.getBytes(StandardCharsets.UTF_8);
String grant_encoded = Base64.getEncoder().encodeToString(authBytes);
hpcon.setRequestProperty("Authorization", "Basic " + grant_encoded);
hpcon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
hpcon.setRequestMethod("POST");
hpcon.setDoInput(true);
hpcon.setDoOutput(true);
hpcon.setUseCaches(false);
Map map = hpcon.getRequestProperties();
for (Map.Entry entry : map.entrySet())
{
System.out.println("Key : " + entry.getKey() + " ,Value : " + entry.getValue());
}
Map hdrs = hpcon.getHeaderFields();
Set hdrKeys = hdrs.keySet();
for (String k : hdrKeys) {
System.out.println("Property Key: " + k + " - Property Value: " + hdrs.get(k));
}
for (Map.Entry entries : hpcon.getRequestProperties().entrySet()) {
String values = "";
for (String value : entries.getValue()) {
values += value + ",";
}
System.out.println("Request - " + entries.getKey() + " - " + values );
}
String postData = "grant_type=client_credentials";
try(OutputStream os = hpcon.getOutputStream()) {
byte[] input = postData.getBytes("utf-8");
os.write(input, 0, input.length);
}
hpcon.connect();
[/code]
Почему, когда я печатаю свойства запроса одним из указанных выше способов, свойство «Авторизация» не появляется?
С уважением.
Стефано Эррани
Подробнее здесь: [url]https://stackoverflow.com/questions/78666594/why-prinnting-httpurlconnection-request-properties-one-of-that-is-not-present[/url]