-
-
Save azumamagus/4e4468cc1b488fa96f7f840405cbdd5d to your computer and use it in GitHub Desktop.
WebClient
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 br.com.teste.agenda; | |
import java.io.PrintStream; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
import java.util.Scanner; | |
public class WebClient { | |
public String post(String json){ | |
try { | |
URL url = new URL("https://www.caelum.com.br/mobile"); | |
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | |
connection.setRequestProperty("Accept", "application/json"); | |
connection.setRequestProperty("Content-type", "application/json"); | |
connection.setDoInput(true); | |
connection.setDoOutput(true); | |
PrintStream saida = new PrintStream(connection.getOutputStream()); | |
saida.println(json); | |
connection.connect(); | |
String resposta = new Scanner(connection.getInputStream()).next(); | |
return resposta; | |
} catch (Exception e){ | |
throw new RuntimeException(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment