Page 1 of 1

curl_setopt no java para consumir APIs

Posted: 05 Nov 2022, 06:07
by javanunes
No PHP as pessoas usam

Code: Select all

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer ' . $token));
$re = curl_exec($ch);
No java as pessoas usam

Code: Select all

  URL obj = new URL(url);
		HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
                conn.setRequestMethod("GET");
                conn.setRequestProperty("User-Agent", "PornoChrome");
		conn.setRequestProperty("Accept", "application/json");
		conn.setRequestProperty("authorization", "Bearer " + token);
                
                
		int responseCode = conn.getResponseCode();
                BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
	        String inputLine;
		StringBuffer response = new StringBuffer();