title: how to use curl command line to access a web page with HTTP Basic Authentication
body: <p>I used to use curl command in terminal to access a php web page to test some APIs in the web page. It works fine.</p>
  
  <p>For example:</p>
  
  <pre><code>curl www.somesite.com -d parmetername=value 
  </code></pre>
  
  <p>Now this page has basic http authentication. I knew I just need to add -u to give the username and password. I also googled and almost everyone suggests to do the same as following:</p>
  
  <pre><code>curl -u username:password www.somesite.com -d parmetername=value
  curl --user username:password www.somesite.com -d parmetername=value 
  </code></pre>
  
  <p>or</p>
  
  <pre><code>curl http://username:password@www.somesite.com -d parmetername=value
  </code></pre>
  
  <p>I have tried both of them, none of them works. I got the same error message as following:</p>
  
  <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;
  &lt;html&gt;&lt;head&gt;
  &lt;title&gt;401 Authorization Required&lt;/title&gt;
  &lt;/head&gt;&lt;body&gt;
  &lt;h1&gt;Authorization Required&lt;/h1&gt;
  &lt;p&gt;This server could not verify that you
  are authorized to access the document
  requested.  Either you supplied the wrong
  credentials (e.g., bad password), or your
  browser doesn't understand how to supply
  the credentials required.&lt;/p&gt;
  &lt;p&gt;Additionally, a 401 Authorization Required
  error was encountered while trying to use an ErrorDocument to handle the request.&lt;/p&gt;
  &lt;hr&gt;
  &lt;address&gt;Apache/2.2.29 (Unix) mod_ssl/2.2.29 OpenSSL/1.0.1e-fips mod_bwlimited/1.4 Server at www.somesite.com Port 80&lt;/address&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>I have tried to access the website via browsers. After I typed in username and password in the prompt window. I can access to this website.</p>
  
  <p>Does anyone know what's going on here?
  Thank you.</p>