Skip to content

Instantly share code, notes, and snippets.

@codemodify
Last active January 17, 2019 11:34
Show Gist options
  • Save codemodify/3181cde47fa2a984ecd58892f804d64e to your computer and use it in GitHub Desktop.
Save codemodify/3181cde47fa2a984ecd58892f804d64e to your computer and use it in GitHub Desktop.
qosmicparticles-io-samples.java
package test;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class Main {
public static void main(String[] args) {
try {
URL url = new URL("http://qosmicparticles.io:4444/FetchGobs");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type","application/json");
String postJsonData = "{" +
"\"version\": \"2.0\"," +
"\"key\": \"rcd1JN+CkZo2+KKR802bXTujubMbiZARQcyTR8Ku8haqdyaz8pA8Z1kbrWJO2J2CiwFdnr\"," +
"\"gobSize\": 96" +
"}";
// Send post request
connection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(postJsonData);
wr.flush();
wr.close();
int responseCode = connection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String output;
StringBuffer response = new StringBuffer();
while ((output = in.readLine()) != null) {
response.append(output);
}
in.close();
//printing result from response
System.out.println(response.toString());
}
catch(Exception ex) {
ex.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment