title: How to access the page protected by basic auth using Faraday?
body: <p>I have a php page I want to access and that page is protected by basic auth. I know the url and username/password, they are listed below in code:</p>
  
  <pre><code>url = 'https://henry.php' # note that it is a php website
  username = 'foo'
  password = 'bar'
  </code></pre>
  
  <p>Faraday provide basic auth function, <a href="https://github.com/lostisland/faraday" rel="nofollow noreferrer">their doc</a> says that I should use the following code:</p>
  
  <pre><code>connection = Faraday.new(url: url) do |conn|
    conn.basic_auth(username, password)
  end 
  </code></pre>
  
  <p>I want to get the response body of the above url to make sure that the basic auth indeed succeed and I can access the content, but I don't know how to. I tried each of the following ways but none of them work:</p>
  
  <pre><code>connection.body
  connection.response.body
  connection.env.response.body
  
  # or
  
  r = connection.get
  r.body
  r.response.body
  r.env.response.body
  
  # or
  
  r = connection.get '/'
  r.body
  r.response.body
  r.env.response.body
  </code></pre>
  
  <p>What is the proper way to get the body?</p>
  
  <p>Note:</p>
  
  <p>In browser, I access <a href="https://henry.php" rel="nofollow noreferrer">https://henry.php</a> directly and browser prompt me a box asking my username and password and I enter them and I can see the content - I can see the details I have is correct and it should work (this is because browser knows how to do basic auth), but I just can't figure out how to do it in code using Faraday.</p>