internet.html
来自「perl教程」· HTML 代码 · 共 1,063 行 · 第 1/5 页
HTML
1,063 行
set to <em>value</em>. The default value for DataSendTimeout is infinite.
See also <code>DataReceiveTimeout</code>, <code>QueryOption</code> and <code>SetOption</code>.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="variable">$HTTP</span><span class="operator">-></span><span class="variable">DataSendTimeout</span><span class="operator">(</span><span class="number">10000</span><span class="operator">);</span>
<span class="variable">$timeout</span> <span class="operator">=</span> <span class="variable">$HTTP</span><span class="operator">-></span><span class="variable">DataSendTimeout</span><span class="operator">();</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_error">Error</a></strong>
<dd>
<p>Returns the last recorded error in the form of an array or string
(depending upon the context) containing the error number and an error
description. Can be applied on any Win32::Internet object (FTP
sessions, etc.). There are 3 types of error you can encounter; they
are recognizable by the error number returned:</p>
</dd>
<ul>
<li><strong><a name="item__2d1">-1</a></strong>
<p>A "trivial" error has occurred in the package. For example, you tried
to use a method on the wrong type of object.</p>
</li>
<li><strong><a name="item_1__2e_2e_11999">1 .. 11999</a></strong>
<p>A generic error has occurred and the Win32::GetLastError error message
is returned.</p>
</li>
<li><strong><a name="item_12000_and_higher">12000 and higher</a></strong>
<p>An Internet error has occurred; the extended Win32 Internet API error
message is returned.</p>
</li>
</ul>
<p>See also <a href="#item_getresponse"><code>GetResponse</code></a>.</p>
<p>Example:</p>
<pre>
<span class="keyword">die</span> <span class="variable">$INET</span><span class="operator">-></span><span class="variable">Error</span><span class="operator">(),</span> <span class="string">qq(\n)</span><span class="operator">;</span>
<span class="operator">(</span><span class="variable">$ErrNum</span><span class="operator">,</span> <span class="variable">$ErrText</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">$INET</span><span class="operator">-></span><span class="variable">Error</span><span class="operator">();</span>
</pre>
<dt><strong><a name="item_fetchurl_url">FetchURL URL</a></strong>
<dd>
<p>Fetch the content of an HTTP, FTP or GOPHER URL. Returns the content
of the file read (or <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> if there was an error and nothing was
read). See also <code>OpenURL</code> and <code>ReadFile</code>.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="variable">$file</span> <span class="operator">=</span> <span class="variable">$INET</span><span class="operator">-></span><span class="variable">FetchURL</span><span class="operator">(</span><span class="string">"http://www.yahoo.com/"</span><span class="operator">);</span>
<span class="variable">$file</span> <span class="operator">=</span> <span class="variable">$INET</span><span class="operator">-></span><span class="variable">FetchURL</span><span class="operator">(</span><span class="string">"ftp://www.activeware.com/contrib/internet.zip"</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_ftp_ftpobject_2c_server_2c_username_2c_password_2c">FTP ftpobject, server, username, password, [port, pasv, context]</a></strong>
<dt><strong><a name="item_ftp_ftpobject_2c_hashref">FTP ftpobject, hashref</a></strong>
<dd>
<p>Opens an FTP connection to server logging in with the given
<em>username</em> and <em>password</em>.</p>
</dd>
<dd>
<p>The parameters and their values are:</p>
</dd>
<ul>
<li><strong><a name="item_server">server</a></strong>
<p>The server to connect to. Default: <em>none</em>.</p>
</li>
<li><strong><a name="item_username">username</a></strong>
<p>The username used to login to the server. Default: anonymous.</p>
</li>
<li><strong><a name="item_password">password</a></strong>
<p>The password used to login to the server. Default: <em>none</em>.</p>
</li>
<li><strong><a name="item_port">port</a></strong>
<p>The port of the FTP service on the server. Default: 21.</p>
</li>
<li><strong><a name="item_pasv">pasv</a></strong>
<p>If it is a value other than 0, use passive transfer mode. Default is
taken from the parent Internet connection object; you can set this
value with the <code>Pasv</code> method.</p>
</li>
<li><strong><a name="item_context">context</a></strong>
<p>A number to identify this operation if it is asynchronous. See
<a href="#item_setstatuscallback"><code>SetStatusCallback</code></a> and <code>GetStatusCallback</code> for more info on
asynchronous operations. Default: <em>none</em>.</p>
</li>
</ul>
<p>If you pass <em>hashref</em> (a reference to an hash array), the following
values are taken from the array:</p>
<pre>
<span class="variable">%hash</span><span class="operator">=(</span>
<span class="string">"server"</span> <span class="operator">=></span> <span class="string">"server"</span><span class="operator">,</span>
<span class="string">"username"</span> <span class="operator">=></span> <span class="string">"username"</span><span class="operator">,</span>
<span class="string">"password"</span> <span class="operator">=></span> <span class="string">"password"</span><span class="operator">,</span>
<span class="string">"port"</span> <span class="operator">=></span> <span class="variable">port</span><span class="operator">,</span>
<span class="string">"pasv"</span> <span class="operator">=></span> <span class="variable">pasv</span><span class="operator">,</span>
<span class="string">"context"</span> <span class="operator">=></span> <span class="variable">context</span><span class="operator">,</span>
<span class="operator">);</span>
</pre>
<p>This method returns <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> if the connection failed, a number
otherwise. You can then call any of the <a href="#ftp_functions">FTP functions</a> as methods
of the newly created <em>ftpobject</em>.</p>
<p>Example:</p>
<pre>
<span class="variable">$result</span> <span class="operator">=</span> <span class="variable">$INET</span><span class="operator">-></span><span class="variable">FTP</span><span class="operator">(</span><span class="variable">$FTP</span><span class="operator">,</span> <span class="string">"ftp.activeware.com"</span><span class="operator">,</span> <span class="string">"anonymous"</span><span class="operator">,</span> <span class="string">"dada\@divinf.it"</span><span class="operator">);</span>
<span class="comment"># and then for example...</span>
<span class="variable">$FTP</span><span class="operator">-></span><span class="variable">Cd</span><span class="operator">(</span><span class="string">"/ntperl/perl5.001m/CurrentBuild"</span><span class="operator">);</span>
</pre>
<pre>
<span class="variable">$params</span><span class="operator">{</span><span class="string">"server"</span><span class="operator">}</span> <span class="operator">=</span> <span class="string">"ftp.activeware.com"</span><span class="operator">;</span>
<span class="variable">$params</span><span class="operator">{</span><span class="string">"password"</span><span class="operator">}</span> <span class="operator">=</span> <span class="string">"dada\@divinf.it"</span><span class="operator">;</span>
<span class="variable">$params</span><span class="operator">{</span><span class="string">"pasv"</span><span class="operator">}</span> <span class="operator">=</span> <span class="number">0</span><span class="operator">;</span>
<span class="variable">$result</span> <span class="operator">=</span> <span class="variable">$INET</span><span class="operator">-></span><span class="variable">FTP</span><span class="operator">(</span><span class="variable">$FTP</span><span class="operator">,\</span><span class="variable">%params</span><span class="operator">);</span>
</pre>
<dt><strong><a name="item_getresponse">GetResponse</a></strong>
<dd>
<p>Returns the text sent by a remote server in response to the last
function executed. It applies on any Win32::Internet object,
particularly of course on <a href="#ftp_functions">FTP sessions</a>. See also
the <a href="#item_error"><code>Error</code></a> function.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="keyword">print</span> <span class="variable">$INET</span><span class="operator">-></span><span class="variable">GetResponse</span><span class="operator">();</span>
<span class="variable">$INET</span><span class="operator">-></span><span class="variable">FTP</span><span class="operator">(</span><span class="variable">$FTP</span><span class="operator">,</span> <span class="string">"ftp.activeware.com"</span><span class="operator">,</span> <span class="string">"anonymous"</span><span class="operator">,</span> <span class="string">"dada\@divinf.it"</span><span class="operator">);</span>
<span class="keyword">print</span> <span class="variable">$FTP</span><span class="operator">-></span><span class="variable">GetResponse</span><span class="operator">();</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_getstatuscallback_context">GetStatusCallback context</a></strong>
<dd>
<p>Returns information about the progress of the asynchronous operation
identified by <em>context</em>; those informations consist of two values: a
status code (one of the INTERNET_STATUS_* <a href="#constants">Constants</a>) and an
additional value depending on the status code; for example, if the
status code returned is INTERNET_STATUS_HANDLE_CREATED, the second
value will hold the handle just created. For more informations on
those values, please refer to the <a href="#microsoft_win32_internet_functions">Microsoft Win32 Internet Functions</a> documentation. See also <a href="#item_setstatuscallback"><code>SetStatusCallback</code></a>.</p>
</dd>
<dd>
<p>Example:</p>
</dd>
<dd>
<pre>
<span class="operator">(</span><span class="variable">$status</span><span class="operator">,</span> <span class="variable">$info</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">$INET</span><span class="operator">-></span><span class="variable">GetStatusCallback</span><span class="operator">(</span><span class="number">1</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_http_httpobject_2c_server_2c_username_2c_password_">HTTP httpobject, server, username, password, [port, flags, context]</a></strong>
<dt><strong><a name="item_http_httpobject_2c_hashref">HTTP httpobject, hashref</a></strong>
<dd>
<p>Opens an HTTP connection to <em>server</em> logging in with the given
<em>username</em> and <em>password</em>.</p>
</dd>
<dd>
<p>The parameters and their values are:</p>
</dd>
<ul>
<li><strong>server</strong>
<p>The server to connect to. Default: <em>none</em>.</p>
</li>
<li><strong>username</strong>
<p>The username used to login to the server. Default: anonymous.</p>
</li>
<li><strong>password</strong>
<p>The password used to login to the server. Default: <em>none</em>.</p>
</li>
<li><strong>port</strong>
<p>The port of the HTTP service on the server. Default: 80.</p>
</li>
<li><strong><a name="item_flags">flags</a></strong>
<p>Additional flags affecting the behavior of the function. Default:
<em>none</em>.</p>
</li>
<li><strong>context</strong>
<p>A number to identify this operation if it is asynchronous. See
<a href="#item_setstatuscallback"><code>SetStatusCallback</code></a> and <code>GetStatusCallback</code> for more info on
asynchronous operations. Default: <em>none</em>.</p>
</li>
</ul>
<p>Refer to the <a href="#microsoft_win32_internet_functions">Microsoft Win32 Internet Functions</a> documentation for
more details on those parameters.</p>
<p>If you pass <em>hashref</em> (a reference to an hash array), the following
values are taken from the array:</p>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?