title: Always got 403 response code when check all link with selenium java
body: <p>I made script for checking all link in one page, but all of the link always give  403 response code, it will opened normally with browser but if checking it by getting response code using selenium java always give 403(Forbidden), i also bring all cookies but it doesn't work, if anyone have solution please let me know.
  Thanks in advance.
  this is my code to store all cookie and bring them in all link response check</p>
  
  <pre class="lang-js prettyprint-override"><code>private int getHttpResponseStatusCode(String webPageUrl) {
    int ret = -1;
    try {
      if (webPageUrl != null &amp;&amp; !"".equals(webPageUrl.trim())) {
        URL urlObj = new URL(webPageUrl.trim());
        HttpURLConnection httpConn = (HttpURLConnection) urlObj.openConnection();
        Set &lt;Cookie&gt; cookies = driver.manage().getCookies();
        String cookieString = "";
        for (Cookie cookie: cookies) {
          cookieString += cookie.getName() + "=" + cookie.getValue() + ";";
        }
        httpConn.addRequestProperty("Cookies", cookieString);
        httpConn.setRequestMethod("HEAD");
        httpConn.connect();
        ret = httpConn.getResponseCode();
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      System.out.println("Http Status Code : " + ret + " , Url : " + webPageUrl);
      return ret;
    }
  };
  </code></pre>
  
  
  
  <p>this is how i get all the link from the page</p>
  
  <pre class="lang-js prettyprint-override"><code>private List &lt;String&gt; parseOutAllUrlLinksInWebPage(String webPageUrl) {
    List &lt;String&gt; retList = new ArrayList &lt;String&gt; ();
    if (webPageUrl != null &amp;&amp; !"".equals(webPageUrl.trim())) {
      /* Get current page belongs domain. */
      String urlDomain = this.getPageBelongDomain(webPageUrl);
      /* First parse out all a tag href urls. */
      By byUrlLink = By.tagName("a");
      List &lt;WebElement&gt; aLinkList = driver.findElements(byUrlLink);
      if (aLinkList != null) {
        int aLinkSize = aLinkList.size();
        for (int i = 0; i &lt;aLinkSize; i++) {
          WebElement aLink = aLinkList.get(i);
          String href = aLink.getAttribute("href");
  
          if (href != null &amp;&amp; !"".equals(href.trim())) {
            /* Only return same domain page url. */
            if (href.toLowerCase().startsWith("http://" + urlDomain) || href.toLowerCase().startsWith("https://" + urlDomain)) {
              retList.add(href);
            }
          }
        }
      }
      /* Second parse out all img tag src urls. */
      By byImg = By.tagName("img");
      List &lt;WebElement&gt; imgList = driver.findElements(byImg);
  
      if (imgList != null) {
        int imgSize = imgList.size();
        for (int i = 0; i &lt;imgSize; i++) {
          WebElement imgElement = imgList.get(i);
          String src = imgElement.getAttribute("src");
  
          if (src != null &amp;&amp; !"".equals(src.trim())) {
            /* Only return same domain page url. */
            if (src.toLowerCase().startsWith("http://" + urlDomain) || src.toLowerCase().startsWith("https://" + urlDomain)) {
              retList.add(src);
            }
          }
        }
      }
    }
    System.out.println("Parse out url completed successfully.");
    return retList;
  };
  </code></pre>