gpt4 book ai didi

https - 使用 httpsurlconnection 类的 urbanairship 出现 401 错误

转载 作者:行者123 更新时间:2023-12-01 23:12:33 24 4
gpt4 key购买 nike

当我尝试点击推送 URL 时出现 401 错误。我正在使用 HTTP BASIC 身份验证,用户名是“Application Key”,密码是“Application Master Secret”。我正在使用 JAVA HttpsUrlConnection 类。我不知道我的代码有什么问题。

 `            URL url = new URL("https://go.urbanairship.com/api/push");
HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestProperty("Content-Type","application/json");
connection.setRequestProperty("Content-Length", Integer.toString(data.length()));

String authString = "xxxxxxxxxxxxxxxxxx:yyyyyyyyyyyyyyyyy";
authString = Base64Coder.encodeString(authString);
connection.setRequestProperty("Authorization","Basic "+ authString);
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(data);
wr.flush();

int responseCode = connection.getResponseCode();

//Get the response
String responseLine = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();`

最佳答案

您的 authString 应该由 <application-key>:<application-master-secret> 组成.此外,您的 authstring 可能未正确编码。尝试使用 Apache Commons Codecostermiller对 authstring 进行编码的库

关于https - 使用 httpsurlconnection 类的 urbanairship 出现 401 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5027295/

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