HEX
Server: Apache
System: Windows NT MAGNETO-ARM 10.0 build 22000 (Windows 10) AMD64
User: Michel (0)
PHP: 7.4.7
Disabled: NONE
Upload Files
File: C:/Ruby27-x64/share/doc/ruby/html/OpenURI.html
<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>module OpenURI - RDoc Documentation</title>

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
</script>

<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<link href="./css/fonts.css" rel="stylesheet">
<link href="./css/rdoc.css" rel="stylesheet">




<body id="top" role="document" class="module">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="./index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  <div id="class-metadata">
    
    
    
    
    
  </div>
</nav>

<main role="main" aria-labelledby="module-OpenURI">
  <h1 id="module-OpenURI" class="module">
    module OpenURI
  </h1>

  <section class="description">
    
<p><a href="OpenURI.html"><code>OpenURI</code></a> is an easy-to-use wrapper for <a href="Net/HTTP.html"><code>Net::HTTP</code></a>, Net::HTTPS and <a href="Net/FTP.html"><code>Net::FTP</code></a>.</p>

<h2 id="module-OpenURI-label-Example">Example<span><a href="#module-OpenURI-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>It is possible to open an http, https or ftp URL as though it were a file:</p>

<pre class="ruby"><span class="ruby-constant">URI</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;http://www.ruby-lang.org/&quot;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">f</span>.<span class="ruby-identifier">each_line</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">line</span>}
}
</pre>

<p>The opened file has several getter methods for its meta-information, as follows, since it is extended by <a href="OpenURI/Meta.html"><code>OpenURI::Meta</code></a>.</p>

<pre class="ruby"><span class="ruby-constant">URI</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;http://www.ruby-lang.org/en&quot;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">f</span>.<span class="ruby-identifier">each_line</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span> <span class="ruby-identifier">p</span> <span class="ruby-identifier">line</span>}
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">base_uri</span>         <span class="ruby-comment"># &lt;URI::HTTP:0x40e6ef2 URL:http://www.ruby-lang.org/en/&gt;</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">content_type</span>     <span class="ruby-comment"># &quot;text/html&quot;</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">charset</span>          <span class="ruby-comment"># &quot;iso-8859-1&quot;</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">content_encoding</span> <span class="ruby-comment"># []</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">last_modified</span>    <span class="ruby-comment"># Thu Dec 05 02:45:02 UTC 2002</span>
}
</pre>

<p>Additional header fields can be specified by an optional hash argument.</p>

<pre class="ruby"><span class="ruby-constant">URI</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;http://www.ruby-lang.org/en/&quot;</span>,
  <span class="ruby-string">&quot;User-Agent&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-node">&quot;Ruby/#{RUBY_VERSION}&quot;</span>,
  <span class="ruby-string">&quot;From&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;foo@bar.invalid&quot;</span>,
  <span class="ruby-string">&quot;Referer&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;http://www.ruby-lang.org/&quot;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
  <span class="ruby-comment"># ...</span>
}
</pre>

<p>The environment variables such as http_proxy, https_proxy and ftp_proxy are in effect by default. Here we disable proxy:</p>

<pre class="ruby"><span class="ruby-constant">URI</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;http://www.ruby-lang.org/en/&quot;</span>, <span class="ruby-value">:proxy</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-keyword">nil</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
  <span class="ruby-comment"># ...</span>
}
</pre>

<p>See <a href="OpenURI/OpenRead.html#method-i-open"><code>OpenURI::OpenRead.open</code></a> and <a href="URI.html#method-c-open"><code>URI.open</code></a> for more on available options.</p>

<p><a href="URI.html"><code>URI</code></a> objects can be opened in a similar way.</p>

<pre class="ruby"><span class="ruby-identifier">uri</span> = <span class="ruby-constant">URI</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-string">&quot;http://www.ruby-lang.org/en/&quot;</span>)
<span class="ruby-identifier">uri</span>.<span class="ruby-identifier">open</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
  <span class="ruby-comment"># ...</span>
}
</pre>

<p><a href="URI.html"><code>URI</code></a> objects can be read directly. The returned string is also extended by <a href="OpenURI/Meta.html"><code>OpenURI::Meta</code></a>.</p>

<pre class="ruby"><span class="ruby-identifier">str</span> = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">read</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">str</span>.<span class="ruby-identifier">base_uri</span>
</pre>
<dl class="rdoc-list note-list"><dt>Author
<dd>
<p>Tanaka Akira &lt;akr@m17n.org&gt;</p>
</dd></dl>

  </section>

  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    
    <section class="constants-list">
      <header>
        <h3>Constants</h3>
      </header>
      <dl>
      
        <dt id="Options">Options
        
        <dd>
        
      
      </dl>
    </section>
    

    

    
  </section>

</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="https://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.1.1.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>