gpt4 book ai didi

android 我怎样才能在 volley 库中处理 setRequestProperty

转载 作者:行者123 更新时间:2023-11-29 15:45:38 24 4
gpt4 key购买 nike

我正在使用 httpurlconnection 类,现在我转向 volley 如何放置授权 token

 HttpURLConnection connection = (HttpURLConnection) client._url.openConnection();
connection.setRequestProperty("Authorization", "Bearer " + client.Token);

提前谢谢你

最佳答案

以下是我在 Volley 项目中经常做的事情:

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("Authorization", "Bearer " + mAccessToken);
return headers;
}

对于基本身份验证情况:

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<>();
String credentials = "username:password";
String auth = "Basic "
+ Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);
headers.put("Content-Type", "application/json");
headers.put("Authorization", auth);
return headers;
}

关于android 我怎样才能在 volley 库中处理 setRequestProperty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33571923/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com