|
BOOL SendResponse( |
|
UINT nClientId, |
|
|
DWORD dwOptions, |
|
|
LPHTTPRESPONSE lpResponse, |
|
|
LPVOID lpvBuffer, |
|
|
DWORD dwLength |
|
); |
Send a response from the server to the specified client.
Parameters
- nClientId
- An unsigned integer which uniquely identifies the client
session.
- dwOptions
- An unsigned integer which specifies how the client request data
will be copied. It may be one of the following values:
Value |
Description |
HTTP_RESPONSE_DEFAULT |
The lpvBuffer parameter is a pointer to a block of
memory that contains the response data. The number of bytes of
data that in the buffer is specified by the dwLength
parameter. This is the same as specifying the
HTTP_RESPONSE_MEMORY option. |
HTTP_RESPONSE_MEMORY |
The lpvBuffer parameter is a pointer
to a block of memory that contains the response data. The number
of bytes of data that in the buffer is specified by the
dwLength parameter. The data will be sent to the client as a
stream of bytes. If the server application was compiled using
Unicode, it is responsibility of the application to convert any
Unicode text to either ANSI or UTF-8, depending on the resource
that was requested by the client. |
HTTP_RESPONSE_STRING |
The lpvBuffer parameter is a pointer to a string
buffer that contains the response data. The maximum number of
bytes of data that will be sent to the client is determined by
the dwLength parameter. If the value of the dwLength
parameter exceeds the string length, the value will be ignored
and the contents of the string will be sent up to the
terminating null character. If the Unicode version of this
method is called, the string will be converted to a byte array
before being sent to the client. |
HTTP_RESPONSE_HGLOBAL |
The lpvBuffer parameter is an HGLOBAL memory handle
which references a block of memory that contains the response
data. The number of bytes of data that in the buffer is
specified by the dwLength parameter. The data will be
sent to the client as a stream of bytes. It is the
responsibility of the application to free the global memory
handle after it is no longer needed. |
HTTP_RESPONSE_FILE |
The lpvBuffer parameter is a pointer to a
string which specifies the name of a file that contains the
response data. If the file does not exist, or does not specify a
regular file, this method will fail. The dwLength
parameter is ignored. If the content type for the specified file
is not explicitly defined in the response, the method will
attempt to automatically determine the correct type based on the
file name extension and/or the contents of the file. |
HTTP_RESPONSE_HANDLE |
The lpvBuffer parameter is a handle to an open file
and the dwLength parameter specifies the number of bytes
to be read from the file and send to the client. If this option
is specified, the response data will be read from the current
position in the file and will advance the file pointer by the
number of bytes sent to the client. |
HTTP_RESPONSE_DYNAMIC |
The response data will be generated dynamically. This
prevents the content length from being included in the response
header, and forces the connection to close, regardless if the
keep-alive option has been specified. This option must be
specified if the application wishes to use the
SendResponseData method to send additional data to the
client. |
HTTP_RESPONSE_NOCACHE |
Informs the client that the data being returned by the
server should not be cached. Typically this is used in
conjunction with the HTTP_RESPONSE_DYNAMIC option when the data
is being generated dynamically. |
- lpResponse
- A pointer to a HTTPRESPONSE structure which contains
additional information about the response to the client. The
structure that is passed by reference to this method must have
the dwSize member initialized to the size of the structure
or the method will fail. This parameter may be NULL, in which
case a default response of "200 OK" is sent to the client along
with any data specified by the lpvBuffer parameter.
- lpvBuffer
- A pointer to the buffer that will contain any response data that
should be sent to the client. The dwOptions parameter
determines if this pointer references a block of memory, a
null-terminated string buffer, a global memory handle or a file
name. This parameter may be NULL, in which case no data will be sent
to the client. If this method is called in response to a HEAD
command being sent by the client, this parameter is ignored.
- dwLength
- An unsigned integer that specifies the number of
bytes of data to be sent to the client. If the lpvBuffer
parameter is NULL, this value must be zero. If this method is
called in response to a HEAD command being sent by the client, this
parameter is ignored.
Return Value
If the method succeeds, the return value is non-zero. If the
method fails, the return value is zero. To get extended error
information, call the GetLastError method.
Remarks
The SendResponse method is called within an OnCommand
event handler to respond to the request made by the client. This
method may only be called once after a command has been received,
and must be called after the ReceiveRequest method. It is only
necessary for the application to call this method if it wants to
implement its own custom handling for a command. It is recommended
that most applications use the default command processing for
standard commands such as GET and POST to ensure that the appropriate
security checks are performed and the response conforms to the
protocol standard.
If the HTTP_RESPONSE_HANDLE option is used to read a copy of the
response data from an open file, the handle must reference a disk file
that was opened using the CreateFile function with
GENERIC_READ access. It cannot be a handle to a device or named pipe.
If the dwLength parameter is larger than the total number of
bytes available to be read from the current position in the file, the
method will stop sending data to the client when it reaches the
end-of-file. If the method succeeds, the file pointer is advanced
by the number of bytes of response data sent to the the client. If
the method fails, the file pointer is returned to its original position
prior to the method being called.
Requirements
Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools11.h
Import Library: cshtsv11.lib
Unicode: Implemented as Unicode and ANSI versions
See Also
RecieveRequest,
SendResponseData,
OnCommand,
HTTPRESPONSE
|
|