Can some one check my code and see I am getting CONNECTION TIMED OUT ERROR

80 views
Skip to first unread message

dhaval...@verizonwireless.com

unread,
Oct 5, 2017, 3:07:48 PM10/5/17
to Bitly API
This is my code 

ublic class BitlyExample{

public void run() throws Exception
{
try{
// String serviceURL = "http://10.74.43.144:5601/chatbot/chatbotLanding/"+ cartid;
// String serviceURL = "http://localhost:5601/chatbot/chatbotLanding/"+ cartid;
// String serviceURL = cartid;
URL myURL = new URL(serviceURL);
String basicAuth = "";
HttpsURLConnection myURLConnection = (HttpsURLConnection) myURL.openConnection();
//HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
myURLConnection.setRequestMethod("GET");
myURLConnection.setRequestProperty("Content-Type", "application/json");
myURLConnection.connect();

InputStream os = new  BufferedInputStream(myURLConnection.getInputStream());
String requestString = "";
os.read(requestString.toString().getBytes());


int HttpResult = myURLConnection.getResponseCode();

if(HttpResult == HttpsURLConnection.HTTP_OK){

StringBuilder serviceResponse = new StringBuilder();

BufferedReader buffer = new BufferedReader(new InputStreamReader(myURLConnection.getInputStream(),"utf-8"));
String line = null;

while ((line = buffer.readLine()) != null) {  
serviceResponse.append(line + "\n");  
}

buffer.close();
boolean validationPass = true;

}
else{
throw new RuntimeException("HTTP Error Code : "+ HttpResult);
}

os.close();
myURLConnection.disconnect();

} catch (Exception e) {
throw new Exception(" Timeout Exception : "+ e.getMessage());
}
}
Reply all
Reply to author
Forward
0 new messages