Server returned HTTP response code: 403 for URL

0 votes
i am building a java application and i am trying to access this url

http://cdn.shephertz.com/repository/files/1617a5da9a4bb32fad94d45f143ae21863bce533d283449d8023a852f787276b/5242b6593a4be2e25dec84b598fbcbe3e929c66a/picture 1.jpeg

somehow i do not know why, i get this error

java.io.IOException: Server returned HTTP response code: 403 for URL: http://cdn.shephertz.com/repository/files/1617a5da9a4bb32fad94d45f143ae21863bce533d283449d8023a852f787276b/5242b6593a4be2e25dec84b598fbcbe3e929c66a/picture 1.jpeg
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection$10.run(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection$10.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at _mouthy.ImageLoader$1.run(ImageLoader.java:32)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://cdn.shephertz.com/repository/files/1617a5da9a4bb32fad94d45f143ae21863bce533d283449d8023a852f787276b/5242b6593a4be2e25dec84b598fbcbe3e929c66a/picture 1.jpeg
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown Source)
    at java.net.URLConnection.getContentType(Unknown Source)
    at _mouthy.ImageLoader$1.run(ImageLoader.java:31)
    ... 1 more

 

and i do not know why, i have tried a whole lot,and all kinds of crazy stuff,  this is currently my code

 

    HttpURLConnection urlc = (HttpURLConnection) new URL(url).openConnection();
                        urlc.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0");
                        urlc.addRequestProperty("Connection", "keep-alive");
                        urlc.addRequestProperty("Referer", "www.google.com");
                        urlc.connect();

 

can someone actually enlighten me? i actually can access it from a web browser, i do not also think its user-agent because i already have that
asked Jul 23, 2015 in Discuss & suggest API by rumorsapp (14 points)

1 Answer

0 votes

Looks like you have space character in your url. Try to encode your URL somethinglike this and it should work fine

 

HttpURLConnection urlc = (HttpURLConnection) new URL(java.net.URLEncoder.encode(url)).openConnection();

 

Let me know if it helps.

 

Thanks

Ajay

answered Jul 24, 2015 by ajay123 (899 points)
it does not work urlMalformedException... im i missing something sir?
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...