How to decode an object via URL?

Asked

Viewed 73 times

2

I have the object URL and I needed to encode and then de-perform, how do I do that? The URL is from a server that displays a Java object encoded and serialized.

  • 4

    Daniel, edit the question with more information, this URL returns a Jsonobject? , your question will end up being closed.

1 answer

2

This may help you. This code opens an HTTP connection and downloads the content. After that, you should only decode the result. If this doesn’t fit, please explain better what you’re trying to do.

package testes;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class DownloadURL {
    public static void main(String[] args) throws IOException {
        HttpURLConnection c1 = (HttpURLConnection) new URL("http://grepcode.com").openConnection();
        int code1 = c1.getResponseCode();
        InputStream resposta = code1 >= 400 ? c1.getErrorStream() : c1.getInputStream();

        System.out.println(code1);
        StringBuilder sb = new StringBuilder(10240);
        int r;
        while ((r = resposta.read()) != -1) {
            sb.append((char) r);
        }
        System.out.println(sb);
    }
}
  • guy will try, but even if it doesn’t work I adapt to my code because that’s exactly what I wanted.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.