-
-
Save dfparker2002/2cdd10672743d6ad84d677edc7c36982 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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