2
獲取取消授權execption同時連接到共享點REST Web服務:的SharePoint REST服務401沒有找到
URL myURL = new URL("http://test:2014/PWA/_api/ProjectData/Projects");
URLConnection uc = myURL.openConnection();
HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
String userCredentials = "admin:pasword";
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary("password".getBytes());
uc.setRequestProperty ("Authorization", basicAuth);
InputStream in = uc.getInputStream();
獲得以下錯誤,同時從URL讀
java.io.IOException: Server returned HTTP response code: 401 for URL: http://test:2014/PWA/_api/ProjectData/Projects
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.jw.sharepoint.examples.XMLParser.getDocumentFromUrl(XMLParser.java:127)
at com.jw.sharepoint.examples.XMLParser.main(XMLParser.java:27)
java.lang.NullPointerException
at com.jw.sharepoint.examples.XMLParser.main(XMLParser.java:29)
401不是'404 - 找不到',而是'未經授權的! – Alexander
@Alexander它使用相同的憑據爲瀏覽器工作,但沒有與java說未經授權的工作。 –
然後您的授權碼可能會被破壞。你確定'String basicAuth =「Basic」+ javax.xml.bind.DatatypeConverter.printBase64Binary(「password」.getBytes()); uc.setRequestProperty(「Authorization」,basicAuth);'做你想做的事情? – Alexander