Beruflich Dokumente
Kultur Dokumente
Extensions
HTTP API Specification
Revision 0.0
October 31, 1994
Microsoft Confidential
Table of Contents
Table of Contents
..............................................................................................................................................................
Revision History
..............................................................................................................................................................
Outstanding Issues
..............................................................................................................................................................
1. Overview
..............................................................................................................................................................
1.1 Goals
................................................................................................................................................
2. API Details
..............................................................................................................................................................
2.1 Constants
................................................................................................................................................
2.2 Types
................................................................................................................................................
2.3 Status Codes
................................................................................................................................................
2.4 APIs
................................................................................................................................................
2.4.1. HttpOpenRequest
.................................................................................................................................
2.4.2. HttpCloseRequest
.................................................................................................................................
2.4.3. HttpAddRequestHeaders
.................................................................................................................................
2.4.4. HttpSendRequest
.................................................................................................................................
2.4.5. HttpReadData
ii
.................................................................................................................................
2.4.6. HttpQueryInfo
.................................................................................................................................
3. Sample Client Code Fragment
..............................................................................................................................................................
iii
Revision History
Version Date Author Description
0.0 31-Oct-1994 KeithMo Created this document.
Outstanding Issues
1.1 Goals
The HTTP API design must meet the following goals:
1. Hide the HTTP protocol from the application. By concentrating all protocol knowlege in a single
DLL, application writers are free to concentrate more on the applications themselves.
2. Allow sophisticated clients access to the raw HTTP data if they think they really need it.
3. Support HTTP protocol extensions (such as the Keep-Connection pragma) to optimize network
bandwidth and system resources when the HTTP DLL is accessing a Windows NT HTTP
Server.
4. Tolerate minor HTTP protocol changes/extensions without requiring API changes.
5. Minimize the number of extraneous RFC822/MIME/HTTP headers sent to the server in the
request block. In other words, don’t send the server a header just to tell it to use a default
value.
6. Leverage off the INET API to enable seemless direct (local) and indirect (Catapult-enabled)
Internet access.
7. Provide ANSI and UNICODE versions of all data types and APIs.
2. API Details
This section details the constants, types, and APIs defined by the INET header file.
2.1 Constants
//
// The default HTTP port for TCP/IP connections.
//
#define HTTP_TCPIP_PORT 80
//
// The default major/minor HTTP version numbers.
//
#define HTTP_MAJOR_VERSION 1
#define HTTP_MINOR_VERSION 0
//
// HttpQueryInfo info levels. Generally, there is one info level
// for each potential RFC822/MIME/HTTP header that an HTTP server
// may send as part of a request response.
//
// The HTTP_QUERY_RAW_HEADERS info level is provided for clients
// that choose to perform their own header parsing.
//
2.2 Types
//
// HHTTPREQ : A handle to an HTTP request.
//
//
// A TCP/IP port.
//
2.4 APIs
All HTTP APIs use a consistent naming convention, function linkage, and decoration. Each API is of the
following form:
INETAPI
<<return_type>>
WINAPI
HttpXxxx(
<<parameters>>
);
The INETAPI decoration allows the APIs to be “declspec’d” for efficiency. The WINAPI linkage specifier
provides consistency with other Win32 APIs.
All HTTP APIs return an easily identified value to indicate a failure condition. Additional error status is
always available via the GetLastError() API.
2.4.1. HttpOpenRequest
Description Opens an HTTP request handle. An HTTP request handle encapsulates a request to be
sent to an HTTP server. The HTTP request handle contains all RFC822/MIME/HTTP
headers to be sent as part of the request.
#define INCL_HTTP
#include <inetapi.h>
INETAPI
HTTPREQ
WINAPI
HttpOpenRequest%(
IN HINET hInternet,
IN LPCTSTR% lpszServerName,
IN PORT nServerPort,
IN LPCTSTR %lpszVerb,
IN LPCTSTR% lpszObjectName,
IN DWORD dwMajorVersion,
IN DWORD dwMinorVersion,
IN LPCTSTR% lpszUserAgent,
IN LPCTSTR% lpszReferer,
IN LPCTSTR% FAR * lplpszAcceptTypes,
IN LPCTSTR% FAR * lplpszAcceptEncodings
);
lpszServerName The name of the target HTTP server. This name may be either
a name resolvable via the RNR APIs, or a dotted IP address
resolvable via the inet_addr() API.
lpszObjectName The target object of the specified verb. This is typically a file
name, an executable module, or a search specifier.
lpszReferer Specifies the address (URI) of the document from which the
URI in the request (lpszObjectName) was obtained. May be
NULL in which case no referer is specified.
Remarks This function creates a new HTTP request handle and stores the specified parameters in
that handle.
Return Value A valid (non-NULL) HTTP request handle if successful, NULL otherwise. Extended
error information is available via the GetLastError() API.
Error Codes
ERROR_INVALID_PARAMETER Invalid parameter.
#define INCL_HTTP
#include <inetapi.h>
INETAPI
BOOL
WINAPI
HttpCloseRequest(
IN HHTTPREQ hHttpRequest
);
Remarks This function closes an open HTTP request handle. All resources associated with the
handle are released, and any open HTTP server connections are aborted.
Return Value TRUE if the function is successful, FALSE otherwise. Extended error information is
available via the GetLastError() API.
Error Codes
ERROR_INVALID_PARAMETER Invalid parameter.
#define INCL_HTTP
#include <inetapi.h>
INETAPI
BOOL
WINAPI
HttpAddRequestHeaders%(
IN HHTTPREQ hHttpRequest,
IN LPCTSTR% lpszHeaders,
IN DWORD dwHeadersLength
);
Remarks This function appends additional “free format” headers to the HTTP request handle.
This API is intended for use by sophisticated clients that need detailed control over the
exact request sent to the HTTP server.
Return Value TRUE if the function is successful, FALSE otherwise. Extended error information is
available via the GetLastError() API.
Error Codes
ERROR_INVALID_PARAMETER Invalid parameter.
#define INCL_HTTP
#include <inetapi.h>
INETAPI
BOOL
WINAPI
HttpSendRequest%(
IN HHTTPREQ hHttpRequest,
IN LPCTSTR% lpszHeaders,
IN DWORD dwHeadersLength,
IN LPVOID lpOptional,
IN DWORD dwOptionalLength
);
dwOptionalLength The length (in BYTEs) of the optional data. This may be zero
if there is no optional data to send.
Remarks This function sends the specified request to the HTTP server. This function allows the
client to specify additional RFC822/MIME/HTTP headers to send along with the
request.
This function also allows the client to specify “optional” data to send to the HTTP server
immediately following the request headers. This feature is typically used for “write”
operations such as PUT and POST.
After the request is sent, this function reads the status code and response headers from
the HTTP server. These headers are maintained internally to the request handle, and are
available to client applications via the HttpQueryInfo() API.
Return Value TRUE if the function is successful, FALSE otherwise. Extended error information is
available via the GetLastError() API.
Error Codes
ERROR_INVALID_PARAMETER Invalid parameter.
#define INCL_HTTP
#include <inetapi.h>
INETAPI
BOOL
WINAPI
HttpReadData(
IN HHTTPREQ hHttpRequest,
OUT LPVOID lpBuffer,
IN OUT LPDWORD lpBufferLength
);
Remarks This function reads a block of data from an outstanding HTTP request. This is typically
used to retrieve object data from a GET operation.
Return Value TRUE if the function is successful, FALSE otherwise. Extended error information is
available via the GetLastError() API.
Error Codes
ERROR_INVALID_PARAMETER Invalid parameter.
#define INCL_HTTP
#include <inetapi.h>
INETAPI
BOOL
WINAPI
HttpQueryInfo%(
IN HHTTPREQ hHttpRequest,
IN DWORD dwInfoLevel,
IN OUT LPTSTR% lpBuffer,
IN OUT LPDWORD lpBufferLength
);
Return Value TRUE if the function is successful, FALSE otherwise. Extended error information is
available via the GetLastError() API.
Error Codes
ERROR_INVALID_PARAMETER Invalid parameter.
//
// Open the Internet.
//
hInternet = InetOpen(
NULL, // lpReserved
0 // dwReserved
);
//
// Open a new request.
//
hHttpRequest = HttpOpenRequest(
hInternet, // hInternet
TEXT(“www.foo.com”), // lpServerName
HTTP_TCPIP_PORT // nServerPort
TEXT(“GET”), // HttpVerb
TEXT(“/default.htm”), // lpszObjectName
HTTP_MAJOR_VERSION, // dwMajorVersion
HTTP_MINOR_VERSION, // dwMinorVersion
TEXT(“Test Client”), // lpszUserAgent
NULL, // lpszReferer
AcceptTypes, // lplpszAcceptTypes
AcceptEncodings // lplpszAcceptEncodings,
);
//
// Send the request.
//
HttpSendRequest(
hHttpRequest, // hHttpRequest
NULL, // lpszAdditional
0, // dwHeadersLength
NULL, // lpOptional
0 // dwOptionalLength
);
//
// Read the raw data, write it to stdout.
//
for( ; ; )
{
dwBufferLength = sizeof(szBuffer);
HttpReadData(
hHttpRequest, // hHttpRequest
szBuffer, // lpBuffer
&dwBufferLength // lpBufferLength
);
if( dwBufferLength == 0 )
{
break;
}
//
// Cleanup.
//