Code example for URLConnection

Methods: connectgetInputStreamgetOutputStreamsetConnectTimeoutsetDoOutputsetRequestProperty

0
 
    static protected InputStream doMqlRead(String query) throws IOException {
        URL url = new URL("http://api.freebase.com/api/service/mqlread");
 
        URLConnection connection = url.openConnection();
        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        connection.setConnectTimeout(5000);
        connection.setDoOutput(true);
         
        DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
        try { 
            String body = "extended=1&query=" + ParsingUtilities.encode(query);
             
            dos.writeBytes(body);
        } finally { 
            dos.flush();
            dos.close();
        } 
         
        connection.connect();
         
        return connection.getInputStream();
    } 
     
    static protected void formulateQuery(Set<String> guids, JSONObject node, Writer writer) throws JSONException {
        JSONWriter jsonWriter = new JSONWriter(writer);
         
Contextual code suggestions in your IDE  Get Codota for Java