Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Make a REST CALL to third party sites #3657

imra9n ·
I am trying to query a server through rest, but getting error 401, while executing as script
groovy:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Base64;
URL url = new URL("URL");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
String userpass = vars.getValue(username) + ":" + vars.getValue(password);
logger.info(vars.getValue(username));
String basicAuth = "Basic " + new String(new Base64().encode(userpass.getBytes()));
conn.setRequestProperty ("Authorization", basicAuth);
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));

String output;
logger.info("Output from Server .... \n");
while ((output = br.readLine()) != null) {
logger.info(output);
}


What is the issue? Is it we can't make third party rest call through groovy.
  • replies 2
  • views 3080
  • stars 0
robinshen ADMIN ·
The server your rest call are connecting to do not authorize your request, please check log of that server for details.
imra9n ·
I was able to make rest call through jersey client. It worked