Jump to content

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


Delision

Recommended Posts

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;
    }

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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