java.io.IOException: Server returned HTTP response code: 403 for URL https://
<p>I am trying to access the URL through browser there is no problem but then my program throws:
<strong>java.io.IOException: Server returned HTTP response code: 403 for URL:</strong> </p>

<p>Here URL is nothing but the attachment file path fro list item on my <strong>Sharepoint Online</strong> server.
I am trying to get the contents of that file.It gets opened from the browser but throws an exception from the code.</p>

<p>Code:</p>

<pre><code>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)) &gt; 0 ) 
            { 
                bais.write(byteChunk, 0, n);                    
            }
    }catch(Exception e)
    {
        throw e;
    }
}
</code></pre>

<p>I have done all the settings in my code and even I tried all the possible solutions which are related to this topic but it still not working.</p>
