Jump to content

Blocked Permission: ("java.util.PropertyPermission" "http.agent" "write") when trying to open a URL connection


Recommended Posts

Posted

I'm trying to read in item prices via the Runescape wiki API, but they block generic requests from anything with the default user agent of Java/{version}, so you have to use:

System.setProperty("http.agent", "Chrome");

In order to not get blocked by them. However, this line seems to be blocked by the OSBot client, because when I have it added I get the error:

Blocked permission: ("java.util.PropertyPermission" "http.agent" "write")

I assume there's a reason the client blocks this, but I'm not sure why. Is there an alternative or a workaround? Here is my full code:

 

public static JsonObject loadItemPrices() throws IOException {
        String sURL = "https://prices.runescape.wiki/api/v1/osrs/latest";

        URL url = new URL(sURL);
        URLConnection request = url.openConnection();
        request.connect();
        JsonParser jp = new JsonParser();
        JsonElement root = null;
        System.setProperty("http.agent", "Chrome");
        try {
            root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
        } catch(Exception e) { 
            
        }
        JsonObject obj = root.getAsJsonObject();
        JsonElement element = obj.get("data");
        JsonObject data = element.getAsJsonObject();
        
        return data;
    }

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...