简体   繁体   English

从Eclipse访问URL时获取org.apache.http.conn.HttpHostConnectException

[英]Getting org.apache.http.conn.HttpHostConnectException while accessing a URL from Eclipse

We are using BrowserStack for a project. 我们正在将BrowserStack用于一个项目。

The portal we are testing is whitelisted for our IP. 我们正在测试的门户已被列入我们IP的白名单。

And we access internet behind proxy. 而且我们在代理后面访问互联网。

While running below code snippet: 在以下代码段下运行时:

public class DemoClass {

public static final String USERNAME = "<Username>";
public static final String AUTOMATE_KEY = "<Key>";
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY 
+ "@hub-cloud.browserstack.com/wd/hub";

public static void main(String[] args) throws Exception {
 String baseUrl;
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("browser", "IE");
caps.setCapability("browser_version", "7.0");
caps.setCapability("os", "Windows");
caps.setCapability("os_version", "XP");
caps.setCapability("browserstack.debug", "true");
caps.setCapability("browserstack.local", "true");
System.getProperties().put("http.proxyHost", "<Proxy URL>");
System.getProperties().put("http.proxyPort", "<Proxy Port>");
WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
....

We are getting below error: 我们遇到以下错误:

Exception in thread "main" 
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a 
new session. Possible causes are invalid address of the remote server or 
browser start-up failure.
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: '<HOSTNAME>', ip: '<HOST IP>', os.name: 'Windows 
7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_131'
Driver info: driver.version: RemoteWebDriver
at 
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:174)
at demopackage.DemoClass.main(DemoClass.java:31)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to hub-
cloud.browserstack.com:443 [hub-cloud.browserstack.com/5.255.92.202] failed: 
Connection refused: connect
.........

How to resolve this issue? 如何解决这个问题?

Here is the Answer to your Question: 这是您的问题的答案:

I din't find any significant issue in your code block as such. 我在您的代码块中没有发现任何重大问题。 But here are a few points you need to take care: 但是,您需要注意以下几点:

  1. When you do WebDriver driver = new RemoteWebDriver(new URL(URL), caps); 当您执行WebDriver driver = new RemoteWebDriver(new URL(URL), caps); remember to import java.net.URL; 记得import java.net.URL;
  2. I have observed you handling the base exception as public static void main(String[] args) throws Exception rather you may consider to be precise by public static void main(String[] args) throws MalformedURLException 我已经观察到您在处理基本异常时将public static void main(String[] args) throws Exception而您可能会考虑通过public static void main(String[] args) throws MalformedURLException
  3. You mentioned We are using BrowserStack for a project but you haven't mentioned whether you are using BrowserStack Automation or BrowserStack Running local tests . 您提到We are using BrowserStack for a project但没有提到您是使用BrowserStack Automation还是正在BrowserStack Running local tests
  4. Assuming you are using BrowserStack Automation you need to remove caps.setCapability("browserstack.local", "true"); 假设您正在使用BrowserStack Automation ,则需要删除caps.setCapability("browserstack.local", "true"); from your code. 从您的代码。
  5. Incase you are using BrowserStack Running local tests you need to mention caps.setCapability("browserstack.local", "true"); 如果您正在使用BrowserStack Running local tests ,则需要提及caps.setCapability("browserstack.local", "true"); in your code. 在您的代码中。
  6. Assuming you are using BrowserStack Automation , here is your own code block along with some simple tweaks which successfully executes on "BrowserStack Automation": 假设您使用的是BrowserStack Automation ,这是您自己的代码块,以及一些简单的调整,它们可以在“ BrowserStack Automation”上成功执行:

     package SeleniumGrid; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import java.net.MalformedURLException; import java.net.URL; public class Q44196893_IE_BrowserStack { public static final String USERNAME = "<Username>"; public static final String AUTOMATE_KEY = "<Key>"; public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub"; public static void main(String[] args) throws MalformedURLException { String baseUrl; DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("browser", "IE"); caps.setCapability("browser_version", "7.0"); caps.setCapability("os", "Windows"); caps.setCapability("os_version", "XP"); caps.setCapability("browserstack.debug", "true"); System.getProperties().put("http.proxyHost", "<Proxy URL>"); System.getProperties().put("http.proxyPort", "<Proxy Port>"); WebDriver driver = new RemoteWebDriver(new URL(URL), caps); driver.get("http://google.com/"); System.out.println("Title is : "+driver.getTitle()); driver.quit(); } } 

Let me know if this Answers your Question. 让我知道这是否回答了您的问题。

Set your proxy in _JAVA_OPTIONS under system variables and it will start working. _JAVA_OPTIONS系统变量下设置代理,它将开始工作。 I faced the same issue and it get resolved by providing proxy for both http and https for _JAVA_OPTIONS . 我遇到了同样的问题,并且通过为_JAVA_OPTIONS提供http和https的代理来解决它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.apache.http.conn.HttpHostConnectException:拒绝连接到http:// localhost - org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused org.apache.http.conn.HttpHostConnectException:连接到127.0.0.1:7055 - org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:7055 在jmeter中收到错误“响应代码:非HTTP响应代码:org.apache.http.conn.HttpHostConnectException” - Getting an error “Response code: Non HTTP response code: org.apache.http.conn.HttpHostConnectException” in jmeter 错误:请求中的异常:org.apache.http.conn.HttpHostConnectException:与http:// ********:80的连接被拒绝 - ERROR:Exception in request: org.apache.http.conn.HttpHostConnectException: Connection to http://********:80 refused 无法将图像从android上传到python Flask服务器,在android中显示错误org.apache.http.conn.HttpHostConnectException - unable to upload image from android to python flask server, show the error org.apache.http.conn.HttpHostConnectException in android Android Studio错误org.apache.http.conn.HttpHostConnectException:拒绝与http://10.0.2.2:8080的连接 - Android Studio error org.apache.http.conn.HttpHostConnectException: Connection to http://10.0.2.2:8080 refused org.apache.http.conn.HttpHostConnectException:连接到127.0.0.1:7055 [/127.0.0.1]失败:连接被拒绝:connect - org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:7055 [/127.0.0.1] failed: Connection refused: connect 线程“ main” org.apache.http.conn.HttpHostConnectException中的异常:连接到//失败:连接超时:connect - Exception in thread “main” org.apache.http.conn.HttpHostConnectException: Connect to // failed: Connection timed out: connect GitLab Runner 不一致:exec-maven-plugin:1.6.0:java org.apache.http.conn.HttpHostConnectException - GitLab Runner Inconsistency: exec-maven-plugin:1.6.0:java org.apache.http.conn.HttpHostConnectException Selenium 3.7:geckodriver:WebDriverException:org.apache.http.conn.HttpHostConnectException连接被拒绝 - Selenium 3.7 : geckodriver : WebDriverException: org.apache.http.conn.HttpHostConnectException Connection Refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM