3 回答
TA贡献1856条经验 获得超17个赞
我正在使用 Volley,但是当我设置标题时,我是这样做的:
HashMap<String, String> headers = new HashMap<String, String>();
String authValue = "Bearer " + apiToken;
headers.put("Authorization", authValue);
headers.put("Accept", "application/json; charset=UTF-8");
headers.put("Content-Type", "application/json; charset=UTF-8");
TA贡献2011条经验 获得超2个赞
“授权”不应是参数。它是一个标题。
HttpPost request = new HttpPost(URL_SECURED_BY_BASIC_AUTHENTICATION);
String auth = DEFAULT_USER + ":" + DEFAULT_PASS;
byte[] encodedAuth = Base64.encodeBase64(
auth.getBytes(StandardCharsets.ISO_8859_1));
String authHeader = "Basic " + new String(encodedAuth);
request.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
HttpClient client = HttpClientBuilder.create().build();
HttpResponse response = client.execute(request);
添加回答
举报