﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-The NoteBook of EricKong-随笔分类-Window编程</title><link>http://www.blogjava.net/jjshcc/category/45665.html</link><description>桑巴葡语翻译工作室是广州市最专业葡萄牙语翻译机构-www.puyufanyi.com-欢迎寻找Java,As400,Mainframe的猎头eric_cc#qq.ccom(把#换成@)</description><language>zh-cn</language><lastBuildDate>Mon, 11 Aug 2014 18:26:12 GMT</lastBuildDate><pubDate>Mon, 11 Aug 2014 18:26:12 GMT</pubDate><ttl>60</ttl><item><title>基于Windows Server 2012 r2环境部署SharePoint 2013 SP1</title><link>http://www.blogjava.net/jjshcc/archive/2014/08/11/416816.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Mon, 11 Aug 2014 08:15:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2014/08/11/416816.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/416816.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2014/08/11/416816.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/416816.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/416816.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 在安装SharePoint 2013 服务器之前，请先了解硬件和软件要求http://technet.microsoft.com/library/cc262485(office.15)?ocid=fwlink#section4Microsoft SharePoint 产品准备工具会为具有内置数据库的单台服务器安装以下必备软件：Web 服务器 (IIS) 角色应用程序服务器角色Microsoft ....&nbsp;&nbsp;<a href='http://www.blogjava.net/jjshcc/archive/2014/08/11/416816.html'>阅读全文</a><img src ="http://www.blogjava.net/jjshcc/aggbug/416816.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2014-08-11 16:15 <a href="http://www.blogjava.net/jjshcc/archive/2014/08/11/416816.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> WinINet 学习资料</title><link>http://www.blogjava.net/jjshcc/archive/2010/07/21/326728.html</link><dc:creator>Eric_jiang</dc:creator><author>Eric_jiang</author><pubDate>Wed, 21 Jul 2010 04:57:00 GMT</pubDate><guid>http://www.blogjava.net/jjshcc/archive/2010/07/21/326728.html</guid><wfw:comment>http://www.blogjava.net/jjshcc/comments/326728.html</wfw:comment><comments>http://www.blogjava.net/jjshcc/archive/2010/07/21/326728.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jjshcc/comments/commentRss/326728.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jjshcc/services/trackbacks/326728.html</trackback:ping><description><![CDATA[1.关于<strong>WinINet</strong> <blockquote>
<div><strong>WinINet</strong>不是给服务端用的，服务端用Microsoft Windows HTTP Services (WinHTTP)</div>
<div><strong>WinINet</strong>抽象了Gopher，FTP，HTTP协议的一些细节。</div>
</blockquote>
<div>2.HINTERNET 句柄</div>
<blockquote>
<h4><font size="2">WinINet</font>函数创建、使用的句柄都是HINTERNET类型的，这种类型的句柄无法被转换成其
它类型的句柄。换句话说，最好别用ReadFile、CloseHandle之类的函数来操作这些句柄。同样的，也别用WinINet函数来访问、操作其
他类型的句柄。比如，用InternetReadFile访问CreateFile创建句柄是无法得到你想要的结果的。想关闭HINTERNET句柄要使
用InternetCloseHandle函数。</h4>
</blockquote>
<h4><font size="2">3.句柄架构</font></h4>
<blockquote> <br />
<div forimg="1" align="center"><img alt="" src="http://www.blogjava.net/images/blogjava_net/jjshcc/技术截图/4e6423d35d403bc8a8ec9a25.jpg.gif" width="357" height="223" /></div>
<br />
<p><a href="http://msdn.microsoft.com/en-us/library/aa385096%28VS.85%29.aspx"><strong>InternetOpen</strong></a> 创建的句柄在顶层，由接下来的一层的 <a href="http://msdn.microsoft.com/en-us/library/aa385098%28VS.85%29.aspx"><strong>InternetOpenUrl</strong></a> 和 <a href="http://msdn.microsoft.com/en-us/library/aa384363%28VS.85%29.aspx"><strong>InternetConnect</strong></a> 使用，而 <a href="http://msdn.microsoft.com/en-us/library/aa384363%28VS.85%29.aspx"><strong>InternetConnect</strong></a> 创建的句柄又被之后的几个函数使用。</p>
<p>下面这张图是依赖 <a href="http://msdn.microsoft.com/en-us/library/aa385098%28VS.85%29.aspx"><strong>InternetOpenUrl</strong></a> 创建的句柄的几个函数，灰色的方框是返回 <strong>HINTERNET</strong> 句柄的函数，而白色的框就是使用被创建的 <strong>HINTERNET</strong> 句柄的函数</p>
<div forimg="1" align="center"><img alt="" src="http://www.blogjava.net/images/blogjava_net/jjshcc/技术截图/254a4152b95258190df3e321.jpg.gif" width="175" height="140" /><br />
</div>
<br />
<h4>FTP Hierarchy</h4>
<h4><font size="2">
<div forimg="1" align="center"><img alt="" src="http://www.blogjava.net/images/blogjava_net/jjshcc/技术截图/0990052a1e471e8c023bf62c.jpg.gif" width="174" height="281" /><br />
<br />
<br />
<div forimg="1" align="center"><img alt="" src="http://www.blogjava.net/images/blogjava_net/jjshcc/1a6e0439887410e43b87ce2d.jpg.gif" width="365" height="183" /><br />
</div>
</div>
<br />
</font></h4>
<h4>HTTP Hierarchy</h4>
<div forimg="1" align="center"><img alt="" src="http://www.blogjava.net/images/blogjava_net/jjshcc/技术截图/92b4ba63dc5341770d33fa28.jpg.gif" width="177" height="230" /><br />
<br />
<br />
<div forimg="1" align="center"><img alt="" src="http://www.blogjava.net/images/blogjava_net/jjshcc/技术截图/a10c1a13ca232334dc540128.jpg.gif" width="185" height="287" /><br />
</div>
</div>
<br />
<p>注意这张图，这张图的意思是 <a href="http://msdn.microsoft.com/en-us/library/aa384318%28VS.85%29.aspx"><strong>HttpSendRequestEx</strong></a> 先访问 <a href="http://msdn.microsoft.com/en-us/library/aa384233%28VS.85%29.aspx"><strong>HttpOpenRequest</strong></a> 创建的句柄之后，  <a href="http://msdn.microsoft.com/en-us/library/aa384230%28VS.85%29.aspx"><strong>HttpEndRequest</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa385105%28VS.85%29.aspx"><strong>InternetReadFileEx</strong></a> 和 <a href="http://msdn.microsoft.com/en-us/library/aa385128%28VS.85%29.aspx"><strong>InternetWriteFile</strong></a> 才能访问这个句柄。 <a href="http://msdn.microsoft.com/en-us/library/aa384230%28VS.85%29.aspx"><strong>HttpEndRequest</strong></a> 被调用之后，才轮的到<a href="http://msdn.microsoft.com/en-us/library/aa385103%28VS.85%29.aspx"><strong>InternetReadFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa385113%28VS.85%29.aspx"><strong>InternetSetFilePointer</strong></a> 和 <a href="http://msdn.microsoft.com/en-us/library/aa385100%28VS.85%29.aspx"><strong>InternetQueryDataAvailable</strong></a> 来访问这个句柄。</p>
</blockquote>
<p>4.内容编码</p>
<blockquote>
<p>HTTP 协议 (RFC 2616) 规定了应用程序可以要求服务器用编码的方式(encoded
format)返回HTTP响应。在Windows Server 2008 与 Windows
Vista之前，发送给应用程序的内容编码了的请求需要应用程序自己处理，从Windows Server 2008 and Windows
Vista开始, 应用程序可以让 <strong>WinINet</strong> 来解码了（gzip与deflate）。有三种方式开启解码选项（基于会话、请求、连接），它们的作用域不同。可以使用<a href="http://msdn.microsoft.com/en-us/library/aa385096%28VS.85%29.aspx"><strong>InternetOpen</strong></a>(基于会话), <a href="http://msdn.microsoft.com/en-us/library/aa384363%28VS.85%29.aspx"><strong>InternetConnect</strong></a>(基于连接),  <a href="http://msdn.microsoft.com/en-us/library/aa384233%28VS.85%29.aspx"><strong>HttpOpenRequest</strong></a>(基于请求)返回的句柄调用<a href="http://msdn.microsoft.com/en-us/library/aa385114%28VS.85%29.aspx"><strong>InternetSetOption</strong></a> 来打开或关闭解码选项,打开则将 <em>dwOption</em> 参数中INTERNET_OPTION_HTTP_DECODING 选项打开, 令 <em>lpBuffer</em> 指向一个为true的boolean变量. 关闭则<em>dwOption</em> 参数中INTERNET_OPTION_HTTP_DECODING 选项打开, 令 <em>lpBuffer</em> 指向一个为false的boolean变量 .</p>
<p>设置解码选项之后， WinInet 在你调用 <a href="http://msdn.microsoft.com/en-us/library/aa385103%28VS.85%29.aspx"><strong>InternetReadFile</strong></a> 是就会执行一次解码。不过就算你打开了解码选项，它也不一定就为你解码&#8230;&#8230;当这种情况发生时， <a href="http://msdn.microsoft.com/en-us/library/aa385103%28VS.85%29.aspx"><strong>InternetReadFile</strong></a> 函数会失败并返回ERROR_INTERNET_DECODING_FAILED.这个时候你可以选择去掉Accept-Encoding头重新发送一次请求，或者把解码关掉然后自己来解码（这时你就得检查Content-Encoding头来判断编码方式了）。</p>
</blockquote>
<p>5.协议无关函数</p>
<ul>
    <li>从Internet下载文件 (<a href="http://msdn.microsoft.com/en-us/library/aa385103%28VS.85%29.aspx"><strong>InternetReadFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa385113%28VS.85%29.aspx"><strong>InternetSetFilePointer</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384698%28VS.85%29.aspx"><strong>InternetFindNextFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa385100%28VS.85%29.aspx"><strong>InternetQueryDataAvailable</strong></a>).</li>
    <li>设置同步操作 (<a href="http://msdn.microsoft.com/en-us/library/aa385120%28VS.85%29.aspx"><strong>InternetSetStatusCallback</strong></a>).</li>
    <li>查询、修改设置 (<a href="http://msdn.microsoft.com/en-us/library/aa385114%28VS.85%29.aspx"><strong>InternetSetOption</strong></a> , <a href="http://msdn.microsoft.com/en-us/library/aa385101%28VS.85%29.aspx"><strong>InternetQueryOption</strong></a>).</li>
    <li>关闭 <a href="http://msdn.microsoft.com/en-us/library/aa383766%28VS.85%29.aspx"><strong>HINTERNET</strong></a> 句柄 (<a href="http://msdn.microsoft.com/en-us/library/aa384350%28VS.85%29.aspx"><strong>InternetCloseHandle</strong></a>).</li>
    <li>锁定、解锁资源文件 (<a href="http://msdn.microsoft.com/en-us/library/aa385095%28VS.85%29.aspx"><strong>InternetLockRequestFile</strong></a> , <a href="http://msdn.microsoft.com/en-us/library/aa385126%28VS.85%29.aspx"><strong>InternetUnlockRequestFile</strong></a>).</li>
</ul>
<table>
    <tbody>
        <tr>
            <td><strong>Function</strong></td>
            <td><strong>Description</strong></td>
        </tr>
        <tr>
            <td><a href="http://msdn.microsoft.com/en-us/library/aa384698%28VS.85%29.aspx"><strong>InternetFindNextFile</strong></a></td>
            <td>继续文件的枚举或搜索. 需要以下函数创建的句柄 <a href="http://msdn.microsoft.com/en-us/library/aa384146%28VS.85%29.aspx"><strong>FtpFindFirstFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384202%28VS.85%29.aspx"><strong>GopherFindFirstFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa385098%28VS.85%29.aspx"><strong>InternetOpenUrl</strong></a></td>
        </tr>
        <tr>
            <td><a href="http://msdn.microsoft.com/en-us/library/aa385095%28VS.85%29.aspx"><strong>InternetLockRequestFile</strong></a></td>
            <td>允许用户锁定文件. 需要以下函数创建的句柄 <a href="http://msdn.microsoft.com/en-us/library/aa384166%28VS.85%29.aspx"><strong>FtpOpenFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384210%28VS.85%29.aspx"><strong>GopherOpenFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384233%28VS.85%29.aspx"><strong>HttpOpenRequest</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa385098%28VS.85%29.aspx"><strong>InternetOpenUrl</strong></a> .</td>
        </tr>
        <tr>
            <td><a href="http://msdn.microsoft.com/en-us/library/aa385100%28VS.85%29.aspx"><strong>InternetQueryDataAvailable</strong></a></td>
            <td>查询可用数据的数量. 需要以下函数创建的句柄 <a href="http://msdn.microsoft.com/en-us/library/aa384166%28VS.85%29.aspx"><strong>FtpOpenFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384210%28VS.85%29.aspx"><strong>GopherOpenFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384233%28VS.85%29.aspx"><strong>HttpOpenRequest</strong></a> .</td>
        </tr>
        <tr>
            <td><a href="http://msdn.microsoft.com/en-us/library/aa385101%28VS.85%29.aspx"><strong>InternetQueryOption</strong></a></td>
            <td>查询 Internet 设置.</td>
        </tr>
        <tr>
            <td><a href="http://msdn.microsoft.com/en-us/library/aa385103%28VS.85%29.aspx"><strong>InternetReadFile</strong></a></td>
            <td>读取 URL 数据. 需要以下函数创建的句柄 <a href="http://msdn.microsoft.com/en-us/library/aa385098%28VS.85%29.aspx"><strong>InternetOpenUrl</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384166%28VS.85%29.aspx"><strong>FtpOpenFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384210%28VS.85%29.aspx"><strong>GopherOpenFile</strong></a>,  <a href="http://msdn.microsoft.com/en-us/library/aa384233%28VS.85%29.aspx"><strong>HttpOpenRequest</strong></a> .</td>
        </tr>
        <tr>
            <td><a href="http://msdn.microsoft.com/en-us/library/aa385113%28VS.85%29.aspx"><strong>InternetSetFilePointer</strong></a></td>
            <td>设置文件指针. 需要以下函数创建的句柄 <a href="http://msdn.microsoft.com/en-us/library/aa385098%28VS.85%29.aspx"><strong>InternetOpenUrl</strong></a> ( HTTP URL only)  <a href="http://msdn.microsoft.com/en-us/library/aa384233%28VS.85%29.aspx"><strong>HttpOpenRequest</strong></a> (GET 方法).</td>
        </tr>
        <tr>
            <td><a href="http://msdn.microsoft.com/en-us/library/aa385114%28VS.85%29.aspx"><strong>InternetSetOption</strong></a></td>
            <td>配置 Internet 设置.</td>
        </tr>
        <tr>
            <td><a href="http://msdn.microsoft.com/en-us/library/aa385120%28VS.85%29.aspx"><strong>InternetSetStatusCallback</strong></a></td>
            <td>设置一个接收状态信息的回调函数. 分配一个回调函数给指定的 <a href="http://msdn.microsoft.com/en-us/library/aa383766%28VS.85%29.aspx"><strong>HINTERNET</strong></a> 句柄及从其演化而来的句柄.</td>
        </tr>
        <tr>
            <td><a href="http://msdn.microsoft.com/en-us/library/aa385126%28VS.85%29.aspx"><strong>InternetUnlockRequestFile</strong></a></td>
            <td>解锁被 <a href="http://msdn.microsoft.com/en-us/library/aa385095%28VS.85%29.aspx"><strong>InternetLockRequestFile</strong></a> 锁定的文件.</td>
        </tr>
    </tbody>
</table>
<h4><font size="2">读文件</font></h4>
<blockquote>
<p>函数 <a href="http://msdn.microsoft.com/en-us/library/aa385103%28VS.85%29.aspx"><strong>InternetReadFile</strong></a> 用来从一个由函数 <a href="http://msdn.microsoft.com/en-us/library/aa385098%28VS.85%29.aspx"><strong>InternetOpenUrl</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384166%28VS.85%29.aspx"><strong>FtpOpenFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384210%28VS.85%29.aspx"><strong>GopherOpenFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384233%28VS.85%29.aspx"><strong>HttpOpenRequest</strong></a> 返回的 <a href="http://msdn.microsoft.com/en-us/library/aa383766%28VS.85%29.aspx"><strong>HINTERNET</strong></a> 句柄下载资源.</p>
<p>WinINet 提供了两种方法来下载整个资源</p>
</blockquote>
<ul>
    <li><a href="http://msdn.microsoft.com/en-us/library/aa385100%28VS.85%29.aspx"><strong>InternetQueryDataAvailable</strong></a> 函数.</li>
    <li>利用 <a href="http://msdn.microsoft.com/en-us/library/aa385103%28VS.85%29.aspx"><strong>InternetReadFile</strong></a> 的返回值</li>
    <p><a href="http://msdn.microsoft.com/en-us/library/aa385100%28VS.85%29.aspx"><strong>InternetQueryDataAvailable</strong></a> 使用 <a href="http://msdn.microsoft.com/en-us/library/aa385098%28VS.85%29.aspx"><strong>InternetOpenUrl</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384166%28VS.85%29.aspx"><strong>FtpOpenFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384210%28VS.85%29.aspx"><strong>GopherOpenFile</strong></a>,  <a href="http://msdn.microsoft.com/en-us/library/aa384233%28VS.85%29.aspx"><strong>HttpOpenRequest</strong></a> (还记得上面的那个图么，这个函数需要在 <a href="http://msdn.microsoft.com/en-us/library/aa384247%28VS.85%29.aspx"><strong>HttpSendRequest</strong></a> 操作该句柄之后才能访问这个句柄) 创建的句柄。返回有效数据的字节数<font face="monospace">，据此，我们就可以分配足够的内存并进行读取，但是这种方法不保险，包头里的长度可能是过时的，而且包头也可能会丢。</font></p>
    <p><font face="monospace">当所有数据都被读完的时候，<strong> <a href="http://msdn.microsoft.com/en-us/library/aa385103%28VS.85%29.aspx">InternetReadFile</a></strong></font> 会返回0字节被读取(<em><font face="monospace">lpdwNumberOfBytesRead</font></em> 参数保存了读取的字节数). 据此，我们就可以循环调用 <a href="http://msdn.microsoft.com/en-us/library/aa385103%28VS.85%29.aspx"><strong>InternetReadFile</strong></a> 直到读取结束。</p>
</ul>
<h4><font face="monospace" size="2">寻找文件</font></h4>
<blockquote>
<p><font face="monospace">先使用 <a href="http://msdn.microsoft.com/en-us/library/aa384146%28VS.85%29.aspx"><strong>FtpFindFirstFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa384202%28VS.85%29.aspx"><strong>GopherFindFirstFile</strong></a>, 或 <a href="http://msdn.microsoft.com/en-us/library/aa385098%28VS.85%29.aspx"><strong>InternetOpenUrl</strong></a> ，然后将其返回的句柄作为参数 传递给 <a href="http://msdn.microsoft.com/en-us/library/aa384698%28VS.85%29.aspx"><strong>InternetFindNextFile</strong></a>  进行继续查找，持续调用 <a href="http://msdn.microsoft.com/en-us/library/aa384698%28VS.85%29.aspx"><strong>InternetFindNextFile</strong></a> 知道返回扩展的错误信息 <a href="http://msdn.microsoft.com/en-us/library/aa385465%28VS.85%29.aspx">ERROR_NO_MORE_FILES</a> 来完成整个搜索，调用 <a href="http://msdn.microsoft.com/en-us/library/ms679360%28VS.85%29.aspx"><strong>GetLastError</strong></a> 来获取最后的错误信息.</font></p>
<p>6.HTTP 会话<br />
</p>
<div forimg="1" align="center"><img alt="" src="http://www.blogjava.net/images/blogjava_net/jjshcc/技术截图/ae9b1efcc8cab295b801a0d7.jpg.gif" width="177" height="230" /><br />
</div>
<br />
<h4>使用 WinINet 函数访问WWW资源</h4>
<h4><font size="2">(1)初始化 WWW 连接</font></h4>
<h4><font size="2">将服务类型设为 INTERNET_SERVICE_HTTP 调用 <a href="http://msdn.microsoft.com/en-us/library/aa384363%28VS.85%29.aspx">InternetConnect</a> 来建立一个 HTTP 会话</font></h4>
<div><font face="monospace">HINTERNET InternetConnect(<br />
__in  HINTERNET <em>hInternet</em>, //InternetOpen 返回的句柄<br />
__in  LPCTSTR <em>lpszServerName</em>, //可以描述目标服务器的字符串<br />
__in  INTERNET_PORT <em>nServerPort</em>,//目标服务器的端口<br />
__in  LPCTSTR <em>lpszUsername</em>,//用户名<br />
__in  LPCTSTR <em>lpszPassword</em>,//密码<br />
__in  DWORD <em>dwService</em>,//使用的服务类型<br />
__in  DWORD <em>dwFlags</em>,<br />
__in  DWORD_PTR <em>dwContext<br />
</em>);</font></div>
<div><em><font face="monospace">nServerPort</font></em></div>
<blockquote>
<table>
    <tbody>
        <tr>
            <td><strong>Value</strong></td>
            <td><strong>Meaning</strong></td>
        </tr>
        <tr>
            <td width="40%">
            <p>INTERNET_DEFAULT_FTP_PORT</p>
            </td>
            <td width="60%">
            <p>Uses the default port for FTP servers (port 21).</p>
            </td>
        </tr>
        <tr>
            <td width="40%">
            <p>INTERNET_DEFAULT_GOPHER_PORT</p>
            </td>
            <td width="60%">
            <p>Uses the default port for Gopher servers (port 70).</p>
            </td>
        </tr>
        <tr>
            <td width="40%">
            <p>INTERNET_DEFAULT_HTTP_PORT</p>
            </td>
            <td width="60%">
            <p>Uses the default port for HTTP servers (port 80).</p>
            </td>
        </tr>
        <tr>
            <td width="40%">
            <p>INTERNET_DEFAULT_HTTPS_PORT</p>
            </td>
            <td width="60%">
            <p>Uses the default port for Secure Hypertext Transfer Protocol (HTTPS) servers (port 443).</p>
            </td>
        </tr>
        <tr>
            <td width="40%">
            <p>INTERNET_DEFAULT_SOCKS_PORT</p>
            </td>
            <td width="60%">
            <p>Uses the default port for SOCKS firewall servers (port 1080).</p>
            </td>
        </tr>
        <tr>
            <td width="40%">
            <p>INTERNET_INVALID_PORT_NUMBER</p>
            </td>
            <td width="60%">
            <p>Uses the default port for the service specified by <em>dwService</em>.</p>
            </td>
        </tr>
    </tbody>
</table>
</blockquote>
<div><em><font face="monospace">ldwService</font></em></div>
<blockquote>
<table>
    <tbody>
        <tr>
            <td><strong>Value</strong></td>
            <td><strong>Meaning</strong></td>
        </tr>
        <tr>
            <td width="40%">
            <p>INTERNET_SERVICE_FTP</p>
            </td>
            <td width="60%">
            <p>FTP service.</p>
            </td>
        </tr>
        <tr>
            <td width="40%">
            <p>INTERNET_SERVICE_GOPHER</p>
            </td>
            <td width="60%">
            <p>Gopher service.</p>
            </td>
        </tr>
        <tr>
            <td width="40%">
            <p>INTERNET_SERVICE_HTTP</p>
            </td>
            <td width="60%">
            <p>HTTP service.</p>
            </td>
        </tr>
    </tbody>
</table>
</blockquote>
<h4><font face="monospace" size="2">(2)建立请求</font></h4>
<p>调用 <a href="http://msdn.microsoft.com/en-us/library/aa384233%28VS.85%29.aspx"><strong>HttpOpenRequest</strong></a> 来建立一个 HTTP 请求，不过这个函数不会自动把请求发送出去，要发送请求需要调用 <a href="http://msdn.microsoft.com/en-us/library/aa384247%28VS.85%29.aspx"><strong>HttpSendRequest</strong></a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa384233%28VS.85%29.aspx"><strong>HttpOpenRequest</strong></a> 原型</p>
<div><font face="monospace"><br />
HINTERNET HttpOpenRequest(<br />
__in  HINTERNET <em>hConnect</em>, <em>// InternetConnect 函数返回的句柄<br />
</em>__in  LPCTSTR <em>lpszVerb</em>, <em>// 动作，有GET, PUT, POST。也可以设置为 NULL ，会被当成默认的 GET 来用<br />
</em>__in  LPCTSTR <em>lpszObjectName</em>, <em>// 一个描述你请求资源的字符串，当请求一个默认页面时令这个参数指向一个空串<br />
</em>__in  LPCTSTR <em>lpszVersion</em>, <em>// HTTP 版本，这个参数为 NULL 时，默认使用""HTTP/1.1""<br />
</em>__in  LPCTSTR <em>lpszReferer</em>, <em>// 说明了lpszObjectName是取自哪个文件，可以设为NULL<br />
</em>__in  LPCTSTR *<em>lplpszAcceptTypes</em>, <em>//</em></font>
<basefont size="2" face="Verdana" />
<em><font color="#ff0000" face="monospace">是一个指向</font></em><font color="#ff0000" face="monospace">LPCTSTR<em>数组的指针！数组以一个NULL指针结束。</em></font><em><font face="monospace">指定了程序接受的内容的类型，设为空则不接受 任何类型的内容，设为空串则等价于""text/*""，即不接受文本文件以外的图片等文件，只接受某种特定的文件可以用类似"image/gif, image/jpeg"的方式。关于更多内容类型 请看<a href="http://www.iana.org/assignments/media-types">这里</a><br />
</font></em><font face="monospace">__in  DWORD <em>dwFlags</em>, <em>// 一般都可以设置为 0<br />
</em>__in  DWORD_PTR <em>dwContext // 一般都可以设置为 0<br />
</em>);</font></div>
<h4><font face="monospace">(3)</font><font face="monospace" size="2">添加请求</font></h4>
<p><a href="http://msdn.microsoft.com/en-us/library/aa384227%28VS.85%29.aspx"><strong><font face="monospace">HttpAddRequestHeaders</font></strong></a> 原型</p>
<div><font face="monospace">BOOL HttpAddRequestHeaders(</font></div>
<div><font face="monospace">&nbsp;&nbsp;          __in  HINTERNET <em>hConnect</em>,//HttpOpenRequest 返回的句柄</font></div>
<div><font face="monospace">&nbsp;&nbsp;          __in  LPCTSTR <em>lpszHeaders</em>,//包含要添加到请求中的头的字符串的指针，每个头都要以一个 CR/LF (</font> "r"n"r"n <font face="monospace">) 对结束</font></div>
<div><font face="monospace">&nbsp;&nbsp;          __in  DWORD <em>dwHeadersLength</em>,//lpszHeaders指向的字符串的长度（以TCHAR类型记）. 如果这个参数被设为-1，则字符串被当作以0结尾的字符串处理，自动计算该字符串的长度</font></div>
<div><font face="monospace">&nbsp;&nbsp;          __in  DWORD <em>dwModifiers</em></font></div>
<div><font face="monospace">);</font></div>
<div><em>dwModifiers</em></div>
<blockquote>
<p>可以是下面这些值的组合</p>
<table>
    <tbody>
        <tr>
            <td><strong>Value</strong></td>
            <td><strong>Meaning</strong></td>
        </tr>
        <tr>
            <td width="40%">
            <p>HTTP_ADDREQ_FLAG_ADD</p>
            </td>
            <td width="60%">
            <p>Adds the header if it does not exist. Used with HTTP_ADDREQ_FLAG_REPLACE.</p>
            </td>
        </tr>
        <tr>
            <td width="40%">
            <p>HTTP_ADDREQ_FLAG_ADD_IF_NEW</p>
            </td>
            <td width="60%">
            <p>Adds the header only if it does not already exist; otherwise, an error is returned.</p>
            </td>
        </tr>
        <tr>
            <td width="40%">
            <p>HTTP_ADDREQ_FLAG_COALESCE</p>
            </td>
            <td width="60%">
            <p>Coalesces headers of the same name.</p>
            </td>
        </tr>
        <tr>
            <td width="40%">
            <p>HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA</p>
            </td>
            <td width="60%">
            <p>Coalesces headers of the same name. For example, adding
            "Accept: text/*" followed by "Accept: audio/*" with this flag results in
            the formation of the single header "Accept: text/*, audio/*". This
            causes the first header found to be coalesced. It is up to the calling
            application to ensure a cohesive scheme with respect to
            coalesced/separate headers.</p>
            </td>
        </tr>
        <tr>
            <td width="40%">
            <p>HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON</p>
            </td>
            <td width="60%">
            <p>Coalesces headers of the same name using a semicolon.</p>
            </td>
        </tr>
        <tr>
            <td width="40%">
            <p>HTTP_ADDREQ_FLAG_REPLACE</p>
            </td>
            <td width="60%">
            <p>Replaces or removes a header. If the header value is
            empty and the header is found, it is removed. If not empty, the header
            value is replaced.</p>
            </td>
        </tr>
    </tbody>
</table>
</blockquote>
<p><strong><font face="monospace" size="3">(4)发送一个请求</font></strong></p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa384247%28VS.85%29.aspx"><strong><font face="monospace">HttpSendRequest</font></strong></a></p>
<div><font face="monospace">BOOL HttpSendRequest(<br />
__in  HINTERNET <em>hRequest</em>, //HttpOpenRequst 返回的句柄<br />
__in  LPCTSTR <em>lpszHeaders</em>, //附加到请求上的头，可以为NULL<br />
__in  DWORD <em>dwHeadersLength</em>, //lpszHeaders指向的字符串的长度（以TCHAR类型记）.
如果这个参数被设为-1，当调用的是HttpSendRequestA时则字符串被当作以0结尾的字符串处理，自动计算该字符串的长度。当调用的是
HttpSendRequestW时就会产生一个错误<br />
__in  LPVOID <em>lpOptional</em>, //当使用POST或PUT方法时，这个参数指向的数据会紧接着请求被发送出去。没有需要发送的数据则可以设置为NULL<br />
__in  DWORD <em>dwOptionalLength //lpOptional数据的字节长度，无数据时设置为0<br />
</em>);</font></div>
<h4><font face="monospace">(5)</font><font face="monospace" size="2">向服务器发送数据</font></h4>
<p><font face="monospace">方法一：参见上面HttpSentRequest的lpOptional参数的说明</font></p>
<p><font face="monospace">方法二：使用 <a href="http://msdn.microsoft.com/en-us/library/aa385128%28VS.85%29.aspx"><strong>InternetWriteFile</strong></a> 向一个句柄里发送数据，然后使用 <a href="http://msdn.microsoft.com/en-us/library/aa384318%28VS.85%29.aspx"><strong>HttpSendRequestEx</strong></a> 发送</font></p>
<h4><font face="monospace">(6)</font><font face="monospace" size="2">查询一个请求的信息</font></h4>
<p><a href="http://msdn.microsoft.com/en-us/library/aa384238%28VS.85%29.aspx"><strong>HttpQueryInfo</strong></a></p>
<div><font face="monospace">BOOL HttpQueryInfo(<br />
__in &nbsp;&nbsp;&nbsp;&nbsp;          HINTERNET <em>hRequest</em>, /*由 HttpOpenRequest 或 InternetOpenUrl 返回的句柄*/<br />
__in &nbsp;&nbsp;&nbsp;&nbsp;          DWORD <em>dwInfoLevel</em>,/*</font> <a href="http://msdn.microsoft.com/en-us/library/aa385351%28VS.85%29.aspx">Query Info Flags</a>.<font face="monospace">*/</font></div>
<div><font face="monospace">&nbsp;&nbsp;          __inout  LPVOID <em>lpvBuffer</em>, /*用于存储查询结果的缓冲区，不可为NULL*/<br />
__inout  LPDWORD <em>lpdwBufferLength</em>,/*lpvBuffer指向的缓冲区的字节长度<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;          若函数执行成功，这个变量存储的是写到缓冲区里的数据长度。如果数据是字符串则返回的长度不包括字符串的结束字符<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;          如果函数发生 ERROR_INSUFFICIENT_BUFFER 错误, 则这个变量里保存的是数据的实际字节长度程序需要根据这个长度重新分配内存，再执行一次这个函数*/<br />
__inout  LPDWORD <em>lpdwIndex /*没看大明白，不过似乎可以设置为NULL<br />
</em> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>Pointer to a zero-based header index used to enumerate multiple headers with the same name.<br />
</em> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>When calling the function, this parameter is the index of the specified header to return.<br />
</em> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>When the function returns, this parameter is the index of the next header.<br />
</em> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>If the next index cannot be found, ERROR_HTTP_HEADER_NOT_FOUND is returned.*/<br />
</em>);</font></div>
<h4><font face="monospace">(7)</font><font face="monospace" size="2">从</font> <font face="monospace">WWW</font> <font face="monospace" size="2">上下载资源</font></h4>
<p><font face="monospace">在调用 <a href="http://msdn.microsoft.com/en-us/library/aa384233%28VS.85%29.aspx"><strong>HttpOpenRequest</strong></a> 和 <a href="http://msdn.microsoft.com/en-us/library/aa384247%28VS.85%29.aspx"><strong>HttpSendRequest</strong></a> 之后， 程序可以使用 <a href="http://msdn.microsoft.com/en-us/library/aa385103%28VS.85%29.aspx"><strong>InternetReadFile</strong></a>, <a href="http://msdn.microsoft.com/en-us/library/aa385100%28VS.85%29.aspx"><strong>InternetQueryDataAvailable</strong></a>,  <a href="http://msdn.microsoft.com/en-us/library/aa385113%28VS.85%29.aspx"><strong>InternetSetFilePointer</strong></a> 来下载HTTP服务器上的资源了。</font></p>
<pre><font face="monospace">BOOL InternetQueryDataAvailable(//查询数据的长度<br />
__in   HINTERNET <em>hFile</em>, //由 InternetOpenUrl, FtpOpenFile, GopherOpenFile, 或 HttpOpenRequest<br />
返回的句柄<br />
__out  LPDWORD <em>lpdwNumberOfBytesAvailable</em>, //用于存放数据长度的指针<br />
__in   DWORD <em>dwFlags</em>, //保留参数，置0<br />
__in   DWORD_PTR <em>dwContext </em>//保留参数，置0<br />
); </font></pre>
<div><font face="monospace">BOOL InternetReadFile( //读取句柄的数据</font></div>
<div><font face="monospace"> __in &nbsp;&nbsp;          HINTERNET hFile, // InternetOpenUrl, FtpOpenFile, GopherOpenFile, HttpOpenRequest 创建的句柄</font></div>
<div><font face="monospace"> __out  LPVOID lpBuffer, // 存放数据的缓冲区</font></div>
<div><font face="monospace"> __in &nbsp;&nbsp;          DWORD dwNumberOfBytesToRead, // 准备读取的字节数</font></div>
<div><font face="monospace"> __out  LPDWORD lpdwNumberOfBytesRead // 读取了的字节数</font></div>
<font face="monospace">);<br />
<br />
DWORD InternetSetFilePointer(
//设置InternetReadFile的文件位置（莫非多线程下载就是用这个实现的？），服务器不支持随机访问的话函数调用会失败，如果
InternetReadFile已经读取到了文件的末尾，这个函数的调用也会失败。<br />
__in  HINTERNET hFile, //由 InternetOpenUrl (on an HTTP or HTTPS URL)创建。
或由HttpOpenRequest 创建(使用 GET 或 HEAD方法，而且句柄已经被 HttpSendRequest 访问过了). <br />
这个句柄也不可以使用 INTERNET_FLAG_DONT_CACHE 或 INTERNET_FLAG_NO_CACHE_WRITE 标志<br />
__in  LONG lDistanceToMove, //移动的字节数。正数向后移动，负数向前移动<br />
__in  PVOID pReserved, //保留参数，为NULL<br />
__in  DWORD dwMoveMethod, //指定了移动指针时的参考点。FILE_BEGIN（使用这个标志时，移动的字节数被当作无符号数处理）、FILE_CURRENT、FILE_END（如果内容的长度无法获得，则使用这个标志时会失败）<br />
__in  DWORD_PTR dwContext //保留参数，为NULL<br />
);</font>
</blockquote>
<img src ="http://www.blogjava.net/jjshcc/aggbug/326728.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jjshcc/" target="_blank">Eric_jiang</a> 2010-07-21 12:57 <a href="http://www.blogjava.net/jjshcc/archive/2010/07/21/326728.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>