CHttpClient::SubmitForm Method  
 
INT SubmitForm(
  LPBYTE lpResult,  
  LPDWORD lpcbResult,  
  DWORD dwOptions  
);
INT SubmitForm(
  HGLOBAL *lpResult,  
  LPDWORD lpcbResult,  
  DWORD dwOptions  
);
INT SubmitForm(
  CString& strResult,  
  DWORD dwOptions  
);

The SubmitForm method submits the contents of the current form to a script on the server and returns the result in a buffer provided by the caller.

Parameters

lpResult
A buffer which will contain the data returned by the server, or a pointer to a global memory handle which will reference the data when the function returns.
lpcbResult
A pointer to an unsigned integer which should be initialized to the maximum number of bytes that can be copied to the buffer specified by the lpvBuffer parameter. If the lpvResult parameter points to a global memory handle, the length value should be initialized to zero. When the function returns, this value will be updated with the actual number of bytes of data that was returned.
dwOptions
An unsigned integer that specifies one or more options. This parameter is constructed by using a bitwise operator with any of the following values:
Value Description
HTTP_SUBMIT_DEFAULT The default post mode. The contents of the buffer are encoded and sent as standard form data. The data returned by the server is copied to the result buffer exactly as it is returned from the server.
HTTP_SUBMIT_CONVERT If the data being returned from the server is textual, it is automatically converted so that the end of line character sequence is compatible with the Windows platform. Individual carriage return or linefeed characters are converted to carriage return/linefeed character sequences. Note that this option does not have any effect on the form data being submitted to the server, only on the data returned by the server.

Return Value

If the function succeeds, the return value is the server result code. If the function fails, the return value is HTTP_ERROR. To get extended error information, call GetLastError.

Remarks

The SubmitForm method is used to submit form data to a script that executes on the server and then copy the output from that script into a local buffer. The method may be used in one of two ways, depending on the needs of the application. The first method is to pre-allocate a buffer large enough to store the resulting output of the script. In this case, the lpvResult parameter will point to the buffer that was allocated by the client and the value that the lpcbResult parameter points to should be initialized to the size of that buffer.

The second method that can be used is have the lpvResult parameter point to a global memory handle which will contain the data when the function returns. In this case, the value that the lpcbResult parameter points to must be initialized to zero. It is important to note that the memory handle returned by the function must be freed by the application, otherwise a memory leak will occur. See the example code below.

This method will cause the current thread to block until the post completes, a timeout occurs or the operation is canceled. During the transfer, the HTTP_EVENT_PROGRESS event will be periodically fired, enabling the application to update any user interface controls. Event notification must be enabled, either by calling EnableEvents, or by registering a callback function using the RegisterEvent function.

To determine the current status of a transaction while it is in progress, use the GetTransferStatus function.

Example

CString strResult;
INT nResult = 0;

pClient->CreateForm(_T("/login.php"), HTTP_METHOD_POST, HTTP_FORM_ENCODED);
pClient->AddField(_T("UserName"), lpszUserName);
pClient->AddField(_T("Password"), lpszPassword);

nResult = pClient->SubmitForm(strResult);
pClient->DestroyForm();

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtpv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also