The following table shows the steps you might perform in a typical HTTP client application:
1. Begin an HTTP session. Create a CInternetSession object. Initializes WinInet and connects to server.
2. Connect to an HTTP server. UseCInternetSession::GetHttpConnection. Returns a CHttpConnection object.
3.Open an HTTP request. Use CHttpConnection::OpenRequest. Returns a CHttpFile object.
4.Send an HTTP request. Use CHttpFile::AddRequestHeaders and CHttpFile::SendRequest. Finds the file. Returns FALSE if the file is not found.
5.Read from the file. UseCHttpFile. Reads the specified number of bytes using a buffer you supply.
6.Handle exceptions. Use theCInternetException class. Handles all common Internet exception types.
7.End the HTTP session. Dispose of theCInternetSession object. Automatically cleans up open file handles and connections.
vc6中有一个例子TEAR: "Tearing" HTML Pages Off the Internet,它是Console形式的,我已试过,很好。对理解整个http操作很好帮助。运行时要带参数,如:
TEAR http://www.sina.com.cn/,会在DOS窗口中打印出所取到的文本内容。该例子使用了HttpAddRequestHeaders,正合你的需要,只不过,你把
const TCHAR szHeaders[] =_T("Accept: text/*\r\nUser-Agent: MFC_Tear_Sample\r\n");
改成
const TCHAR szHeaders[] =_T("Accept: text/*\r\nUser-Agent: MFC_Tear_Sample\r\nReferer: http://you.want.com/somepage.htm\r\n");
即可达到你的准确目标
The HTTP functions described in this section control the transmission and content of HTTP requests.
HttpAddRequestHeaders : Adds one or more HTTP request headers to the HTTP request handle.
HttpEndRequest : Ends an HTTP request that was initiated by HttpSendRequestEx.
HttpOpenRequest : Creates an HTTP request handle.
HttpQueryInfo : Retrieves header information associated with an HTTP request.
HttpSendRequest : Sends the specified request to the HTTP server.
HttpSendRequestEx : Sends the specified request to the HTTP server and allows chunked transfers.
也可使用CHttpConnection,CHttpFile等对http functions的封装类(vc中有)来编程,(AddRequestHeaders是CHttpFile的成员函数),
大致流程是先建立连接,获得请求handle,使用AddRequestHeaders函数对handle添加请求头,再使用HttpSendRequest函数真正发送请求,具体函数用法请参见函数说明
我也没有这方面的例子,但大致是这样。