我尝试使用身份验证值向服务器发送响应,它在登录时提供给我。服务器仅在发送该值时才接受请求。然而,它适用于 postman (see snapshot)但不是我的代码。
代码
URL url = new URL(strings[0]);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
String token = "" + new String(accessToken);
con.setRequestMethod("GET");
con.setRequestProperty("AuthToken", token);
con.setReadTimeout(15000);
con.setConnectTimeout(15000);
con.setDoOutput(false);
我也试过这种方法
String token = "AuthToken :" + new String(accessToken);
con.setRequestProperty("Authorization", token);
最佳答案
试试这个
URL url = new URL(strings[0]);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
String token = "" + new String(accessToken);
con.setRequestMethod("GET");
con.setRequestProperty("AuthToken", token);
con.setReadTimeout(15000);
con.setConnectTimeout(15000);
con.setDoOutput(false);
关于android - 使用 HttpUrlConnection 发送 header 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43320017/