Skip to content

Instantly share code, notes, and snippets.

@dfparker2002
Forked from aanchalsikka/CurlExecutor.java
Created February 12, 2022 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfparker2002/2cdd10672743d6ad84d677edc7c36982 to your computer and use it in GitHub Desktop.
Save dfparker2002/2cdd10672743d6ad84d677edc7c36982 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