Skip to content

Instantly share code, notes, and snippets.

@aanchalsikka
Created January 19, 2018 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aanchalsikka/2bb0b9a0e5b530f78596dcb8ee7df579 to your computer and use it in GitHub Desktop.
Save aanchalsikka/2bb0b9a0e5b530f78596dcb8ee7df579 to your computer and use it in GitHub Desktop.
package blog.techrevel.api;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import org.apache.commons.codec.binary.Base64;
public class CurlExecutor {
public static void main(String[] args) {
String stringUrl = "http://localhost:4502/system/console/bundles.json";
URL url;
try {
url = new URL(stringUrl);
URLConnection uc;
uc = url.openConnection();
uc.setRequestProperty("X-Requested-With", "Curl");
String userpass = "admin" + ":" + "admin";
String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes()));
uc.setRequestProperty("Authorization", basicAuth);
BufferedReader reader = new BufferedReader(new InputStreamReader(uc.getInputStream()));
StringBuilder builder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
builder.append(line);
builder.append(System.getProperty("line.separator"));
}
String result = builder.toString();
System.out.println(result);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment