Skip to content

Instantly share code, notes, and snippets.

@leonardocordeiro
Created June 12, 2017 15:33
Show Gist options
  • Save leonardocordeiro/ee593a5a1f35d53bd292a2c4eed95cf5 to your computer and use it in GitHub Desktop.
Save leonardocordeiro/ee593a5a1f35d53bd292a2c4eed95cf5 to your computer and use it in GitHub Desktop.
cliente sse com urlconnection
package org.lema.notasapp.infra.filter;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
/**
* Created by leonardocordeiro on 11/06/17.
*/
public class Teste {
public static void main(String[] args) throws Exception {
HttpURLConnection url = (HttpURLConnection) new URL("...").openConnection();
url.setRequestProperty("Content-type", "text/event-stream");
url.setRequestProperty("Accept", "text/event-stream");
url.setRequestMethod("GET");
InputStream inputStream = url.getInputStream();
Scanner s = new Scanner(inputStream);
while(s.hasNextLine()) {
System.out.println("args = " + s.nextLine());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment