package rs.bspk.drunkenadventure;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
public class DrunkenAdventureMain
{
/**
* @param args
*/
public static void main(String[] args)
{
byte[] bytesData;//byte array with file data
URL url;
try
{
url = new URL("http://api.stor.ag/v2/cfs/");
//Configure connection
HttpURLConnection conn;
try
{
conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
try
{
conn.setRequestMethod("POST");
}
catch (ProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
conn.setReadTimeout(60000);
//Set headers
conn.setRequestProperty("Storage-Key", "REDACTED");
conn.setRequestProperty("CFS-name", "test");
System.out.println(conn.getResponseCode() + " --- " + conn.getResponseMessage());
//Check connection
// if (conn.getResponseCode() != HttpURLConnection.HTTP_OK)
// {
// throw new RuntimeException("FAILED!!! HTTP error code: " +
// conn.getResponseCode() + " --- " +
// conn.getResponseMessage());
// }
//Get response
System.out.println("\nGetting response...");
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
//Print response
System.out.println("\nOutput from Server .... \n");
String output;
while ((output = br.readLine()) != null)
{
System.out.println(output);
}
}
catch (IOException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Comments