401使用httpsurlconnection类的urbanairship出现错误
当我尝试点击推送URL时,我遇到了一个401错误。我使用HTTP基本身份验证,用户名为“应用程序密钥”,密码为“应用程序主密钥”。我正在使用JAVA HttpsUrlConnection类。我不知道我的代码有什么问题401使用httpsurlconnection类的urbanairship出现错误,https,push-notification,urbanairship.com,Https,Push Notification,Urbanairship.com,当我尝试点击推送URL时,我遇到了一个401错误。我使用HTTP基本身份验证,用户名为“应用程序密钥”,密码为“应用程序主密钥”。我正在使用JAVA HttpsUrlConnection类。我不知道我的代码有什么问题 ` URL url = new URL("https://go.urbanairship.com/api/push"); HttpsURLConnection connection = (HttpsURLConnection)url.op
` 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应该由
或库组成,以编码authString,即使在上述代码中添加“ostermiller”库也会出现相同的错误…有什么建议吗??