Module 14- getResponseCode method is giving error even after adding fluent-hc-4.2.2 . jar. Underlined code is giving problem. | Selenium Forum
B
barik.arun Posted on 18/03/2020

import java.util.concurrent.TimeUnit;
import org.apache.http.client.fluent.Request;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.http.HttpResponse;

public class ResponseCode {
public static void main(String[] args) {

System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");

WebDriver driver= new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://www.cnn.com/");
boolean bol=getResponseCode("http://cnn.com");


}

public static boolean getResponseCode(String url){
int resp_code=0;
try {
resp_code = Request.Get(url).execute().returnResponse().getStatusLine()
.getStatusCode();

System.out.println("Respose code for URL "+ url +" is -> "+ resp_code);

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

if(resp_code==200)
return true;
else
return false;
}

 

}


A
Ashish Thakur Replied on 18/03/2020

To investigate the issue, we need the complete exception stack trace.

Please share the same.