Sophie

Sophie

distrib > Fedora > 17 > i386 > media > updates > by-pkgid > 675c8c8167236dfcf8d66da674f931e8 > files > 778

erlang-doc-R15B-03.3.fc17.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../../../doc/otp_doc.css" type="text/css">
<title>Erlang -- HTTP Client</title>
</head>
<body bgcolor="white" text="#000000" link="#0000ff" vlink="#ff00ff" alink="#ff0000"><div id="container">
<script id="js" type="text/javascript" language="JavaScript" src="../../../../doc/js/flipmenu/flipmenu.js"></script><script id="js2" type="text/javascript" src="../../../../doc/js/erlresolvelinks.js"></script><script language="JavaScript" type="text/javascript">
            <!--
              function getWinHeight() {
                var myHeight = 0;
                if( typeof( window.innerHeight ) == 'number' ) {
                  //Non-IE
                  myHeight = window.innerHeight;
                } else if( document.documentElement && ( document.documentElement.clientWidth ||
                                                         document.documentElement.clientHeight ) ) {
                  //IE 6+ in 'standards compliant mode'
                  myHeight = document.documentElement.clientHeight;
                } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
                  //IE 4 compatible
                  myHeight = document.body.clientHeight;
                }
                return myHeight;
              }

              function setscrollpos() {
                var objf=document.getElementById('loadscrollpos');
                 document.getElementById("leftnav").scrollTop = objf.offsetTop - getWinHeight()/2;
              }

              function addEvent(obj, evType, fn){
                if (obj.addEventListener){
                obj.addEventListener(evType, fn, true);
                return true;
              } else if (obj.attachEvent){
                var r = obj.attachEvent("on"+evType, fn);
                return r;
              } else {
                return false;
              }
             }

             addEvent(window, 'load', setscrollpos);

             //--></script><div id="leftnav"><div class="innertube">
<img alt="Erlang logo" src="../../../../doc/erlang-logo.png"><br><small><a href="users_guide.html">User's Guide</a><br><a href="index.html">Reference Manual</a><br><a href="release_notes.html">Release Notes</a><br><a href="../pdf/inets-5.9.2.pdf">PDF</a><br><a href="../../../../doc/index.html">Top</a></small><p><strong>inets</strong><br><strong>User's Guide</strong><br><small>Version 5.9.2</small></p>
<br><a href="javascript:openAllFlips()">Expand All</a><br><a href="javascript:closeAllFlips()">Contract All</a><p><small><strong>Chapters</strong></small></p>
<ul class="flipMenu" imagepath="../../../../doc/js/flipmenu">
<li id="no" title="Introduction" expanded="false">Introduction<ul>
<li><a href="inets_services.html">
              Top of chapter
            </a></li>
<li title="Purpose"><a href="inets_services.html#id57726">Purpose</a></li>
<li title="Prerequisites"><a href="inets_services.html#id63179">Prerequisites</a></li>
<li title="The Service Concept"><a href="inets_services.html#id59584">The Service Concept</a></li>
</ul>
</li>
<li id="no" title="FTP Client" expanded="false">FTP Client<ul>
<li><a href="ftp_client.html">
              Top of chapter
            </a></li>
<li title="Introduction"><a href="ftp_client.html#id61235">Introduction</a></li>
<li title="Using the FTP Client API"><a href="ftp_client.html#id57000">Using the FTP Client API</a></li>
</ul>
</li>
<li id="loadscrollpos" title="HTTP Client" expanded="true">HTTP Client<ul>
<li><a href="http_client.html">
              Top of chapter
            </a></li>
<li title="Introduction"><a href="http_client.html#id60140">Introduction</a></li>
<li title="Configuration"><a href="http_client.html#id61256">Configuration</a></li>
<li title="Using the HTTP Client API"><a href="http_client.html#id60633">Using the HTTP Client API</a></li>
</ul>
</li>
<li id="no" title="HTTP server " expanded="false">HTTP server <ul>
<li><a href="http_server.html">
              Top of chapter
            </a></li>
<li title="Introduction"><a href="http_server.html#id61031">Introduction</a></li>
<li title="Configuration"><a href="http_server.html#id60316">Configuration</a></li>
<li title="Using the HTTP Server API"><a href="http_server.html#id60564">Using the HTTP Server API</a></li>
<li title="Htaccess - User Configurable Authentication."><a href="http_server.html#id61824">Htaccess - User Configurable Authentication.</a></li>
<li title="Dynamic Web Pages"><a href="http_server.html#id60221">Dynamic Web Pages</a></li>
<li title="Logging "><a href="http_server.html#id62487">Logging </a></li>
<li title="Server Side Includes"><a href="http_server.html#id62597">Server Side Includes</a></li>
<li title="The Erlang Web Server API"><a href="http_server.html#id62269">The Erlang Web Server API</a></li>
<li title="Inets Web Server Modules"><a href="http_server.html#id62373">Inets Web Server Modules</a></li>
</ul>
</li>
</ul>
</div></div>
<div id="content">
<div class="innertube">
<h1>3 HTTP Client</h1>
  

  <h3><a name="id60140">3.1 
        Introduction</a></h3>
    

    <p>The HTTP client default profile will be started when the inets
    application is started and is then available to all processes on
    that erlang node. Other profiles may also be started at
    application startup, or profiles can be started and stopped
    dynamically in runtime. Each client profile will spawn a new
    process to handle each request unless there is a possibility to use
    a persistent connection with or without pipelining.
    The client will add a <span class="code">host</span> header and an empty
    <span class="code">te</span> header if there are no such headers present in the request.</p>

    <p>The client supports ipv6 as long as the underlying mechanisms also do
      so.</p>
  

  <h3><a name="id61256">3.2 
        Configuration</a></h3>
    
    <p> What to put in the erlang node application configuration file
      in order to start a profile at application startup.</p>
    <div class="example"><pre>
      [{inets, [{services, [{httpc, PropertyList}]}]}]
    </pre></div>
    <p>For valid properties see 
    <span class="bold_code"><a href="httpc.html">httpc(3)</a></span>. </p>
  

  <h3><a name="id60633">3.3 
        Using the HTTP Client API</a></h3>
    
    <div class="example"><pre>
 1 &gt; inets:start().
      ok
    </pre></div>
    <p> The following calls uses the default client profile.
      Use the proxy "www-proxy.mycompany.com:8000",
      but not for requests to localhost. This will apply to all subsequent
      requests</p>
    <div class="example"><pre>
      2 &gt; httpc:set_options([{proxy, {{"www-proxy.mycompany.com", 8000},
      ["localhost"]}}]).
      ok
    </pre></div>
    <p>An ordinary synchronous request. </p>
    <div class="example"><pre>
      3 &gt; {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} =
      httpc:request(get, {"http://www.erlang.org", []}, [], []).
    </pre></div>
    <p>With all default values, as above, a get request can also be written
      like this.</p>
    <div class="example"><pre>
      4 &gt; {ok, {{Version, 200, ReasonPhrase}, Headers, Body}} =
      httpc:request("http://www.erlang.org").
    </pre></div>
    <p>An ordinary asynchronous request. The result will be sent
      to the calling process in the form <span class="code">{http, {ReqestId, Result}}</span></p>
    <div class="example"><pre>
      5 &gt; {ok, RequestId} =
      httpc:request(get, {"http://www.erlang.org", []}, [], [{sync, false}]).
    </pre></div>
    <p>In this case the calling process is the shell, so we receive the
      result.</p>
    <div class="example"><pre>
      6 &gt; receive {http, {RequestId, Result}} -&gt; ok after 500 -&gt; error end.
      ok
    </pre></div>
    <p>Send a request with a specified connection header. </p>
    <div class="example"><pre>
      7 &gt; {ok, {{NewVersion, 200, NewReasonPhrase}, NewHeaders, NewBody}} =
      httpc:request(get, {"http://www.erlang.org", [{"connection", "close"}]},
      [], []).
    </pre></div>

    <p>Start a HTTP client profile. </p>
   
    <div class="example"><pre>
      8 &gt; {ok, Pid} = inets:start(httpc, [{profile, foo}]).
      {ok, &lt;0.45.0&gt;}       
      </pre></div>
    
    <p>The new profile has no proxy settings so the connection will
      be refused</p>
      <div class="example"><pre>
      9 &gt; httpc:request("http://www.erlang.org", foo). 
      {error, econnrefused}
    </pre></div>

    <p>Stop a HTTP client profile. </p>
    <div class="example"><pre>
      10 &gt; inets:stop(httpc, foo).
      ok
    </pre></div>
    
    <p>Alternatively:</p>
    <div class="example"><pre>
      10 &gt; inets:stop(httpc, Pid).
      ok
    </pre></div>
    
  
</div>
<div class="footer">
<hr>
<p>Copyright © 1997-2012 Ericsson AB. All Rights Reserved.</p>
</div>
</div>
</div></body>
</html>