【发布时间】:2018-01-31 20:28:47
【问题描述】:
我遇到了无法设置“授权”标头的问题。 我能够设置其余的标题,但是当我使用特定的键时,我无法设置任何数据。请帮忙。
URL myURL = new URL(url);
HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
String basicAuth = "Bearer 6f6b06fe-131e-314b-9ef8-42f2cbdcfc18";
myURLConnection.setRequestMethod("GET");
myURLConnection.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
myURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
myURLConnection.setRequestProperty("Content-Language", "en-US");
myURLConnection.setRequestProperty("Authorization", "basicAuth");
myURLConnection.setUseCaches(false);
myURLConnection.setDoInput(true);
myURLConnection.setDoOutput(true);
System.out.println(myURLConnection.getRequestProperties());
希望尽快听到。谢谢。
【问题讨论】:
-
你怎么知道 header 没有设置
-
“我无法设置任何数据”。以什么方式?
-
替换这个 myURLConnection.setRequestProperty("Authorization", "basicAuth");与 myURLConnection.setRequestProperty("Authorization", basicAuth);
-
嗨,Ivar,我发现标题中没有占用数据的唯一实例是我使用“授权”时。我什至尝试了“TEST”,然后就进去了。
标签: java apache httpurlconnection urlconnection