本帖末尾给定片段的响应http代码为403. 403表示禁止。但我正在访问并通过谷歌chrome POSTman应用程序发布到它。在这种情况下,我无法解决问题。我尝试了许多其他解决方案,如:
httpURLConnection.setRequestProperty("授权","基本" +标题);
httpURLConnection.setRequestProperty(" ApiKey"" ABCD1234&#34);
HttpURLConnection httpURLConnection = (HttpURLConnection) (new URL ("http:abc.com")).openConnection();
httpURLConnection.setDoOutput(true);
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setRequestProperty("Authorization",Header);
// Header = "ApiKey:abcd1234" ;
httpURLConnection.setRequestProperty("Content-Type","application/json");
答案 0 :(得分:0)
BASIC身份验证数据需要使用baase64编码,类似于
String encoded = Base64.encode(username+":"+password); connection.setRequestProperty("Authorization", "Basic "+encoded);