ブラウザを介してURLにアクセスしようとしていますが、問題はありませんが、プログラムは次のようにスローします 。java.io.IOException:サーバーがHTTP応答コードを返しました:URLの403:
ここで、URLは、 SharepointOnlineサーバー上のリストアイテムの添付ファイルパスに他なりません。そのファイルの内容を取得しようとしています。ブラウザから開かれますが、コードから例外がスローされます。
コード:
private String getAttachmentContent(String attachmentURL) throws IBSharePointException 
{
    InputStream is = null;
    try 
    {
        String fileName=attachmentURL.substring(attachmentURL.lastIndexOf("/")+1);
        String urlPath=attachmentURL.substring(0, attachmentURL.lastIndexOf("/")+1);
        fileName=URLEncoder.encode(fileName, "UTF-8");
        if(fileName.contains("+"))
            fileName=fileName.replace("+", "%20");          
        URL u=new URL(urlPath+fileName);    
        // Following Line Throws Exception : java.io.IOException: Server returned HTTP response code: 403 for URL:
        is = u.openStream();
        ByteArrayOutputStream bais = new ByteArrayOutputStream();
        byte[] byteChunk = new byte[4096];    
        int n;    
        while ( (n = is.read(byteChunk)) > 0 ) 
            { 
                bais.write(byteChunk, 0, n);                    
            }
    }catch(Exception e)
    {
        throw e;
    }
}
私は自分のコードですべての設定を行い、このトピックに関連するすべての可能な解決策を試しましたが、それでも機能しません。