简体   繁体   中英

Apache url not Accessible

I have to check the access of a apache server.I have written a standalone code for cheking the access of a apache server. If i simply type the url it is accessable...But wen i run it through code it throws exception..

as java.io.IOException: Server returned HTTP response code: 403 for URL: http://10.98.12.151:80/server-status?auto

What is 403 response code?? hw can i make it accessible from standalone code...

This is my code connecturl = "http://" + ip + ":" + port + "/server-status?auto"; targetURL = new URL(connecturl); HttpURLConnection httpURLConnection = (HttpURLConnection) targetURL.openConnection();

        httpURLConnection.setUseCaches(false);

        httpURLConnection.setAllowUserInteraction(false);

        httpURLConnection.setDoInput(true);

        httpURLConnection.setRequestMethod("GET");


        httpURLConnection.connect();

The 403 code is an "access denied" code. Other codes definitions can be found at w3.org

The cause is likely due to directive in your httpd.conf file not having an "Allow from" that includes the ip of the host you're trying to run the program on.

For example, you're trying running this from a client (10.98.12.10) and want to check the status of the webserver you have running on 10.98.12.151.

Make sure the httpd.conf file on the server has something like the following:

<Location /server-status>
  SetHandler server-status
  Order deny,allow
  Deny from all
# now make sure your client host is allowed to connect to this location
  Allow from 10.98.12.10
</Location>

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM